Skip to content

Commit 2bab2c3

Browse files
committed
experiment
1 parent 601a5b4 commit 2bab2c3

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/main/java/org/janelia/saalfeldlab/n5/KeyLockState.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ private void releaseFileLock() {
173173

174174
void releaseLock() {
175175

176+
System.out.println("KeyLockState.releaseLock");
176177
final boolean isWrite = threadLock.isWriteLockedByCurrentThread();
177178

178179
synchronized (this) {
@@ -181,6 +182,7 @@ void releaseLock() {
181182
releaseFileLock();
182183
} else {
183184
readLockHolders--;
185+
System.out.println(" readLockHolders = " + readLockHolders);
184186
if (readLockHolders == 0) {
185187
releaseFileLock();
186188
}

src/test/java/org/janelia/saalfeldlab/n5/FileKeyLockManagerTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,33 @@ public void tearDown() throws IOException {
7676
}
7777
}
7878

79+
private void lockunlock(final Path testFile) throws IOException {
80+
LockedChannel lock1 = FILE_LOCK_MANAGER.lockForReading(testFile);
81+
lock1.close();
82+
}
83+
84+
@Test
85+
public void testCleanup() throws Exception {
86+
/* create a test file */
87+
final Path testFile = tempDir.resolve("test.txt");
88+
final String testContent = "test";
89+
Files.write(testFile, testContent.getBytes());
90+
91+
LockedChannel lock1 = FILE_LOCK_MANAGER.lockForReading(testFile);
92+
LockedChannel lock2 = FILE_LOCK_MANAGER.lockForReading(testFile);
93+
System.out.println("lock1.close");
94+
lock1.close();
95+
lock1 = null;
96+
for (int i = 0; i < 10; i++) {
97+
System.out.println("lockunlock");
98+
lockunlock(testFile);
99+
System.gc();
100+
Thread.sleep(500);
101+
}
102+
System.out.println("lock2.close");
103+
lock2.close();
104+
}
105+
79106
@Test
80107
public void testConcurrentReads() throws Exception {
81108

0 commit comments

Comments
 (0)