Skip to content

Commit

Permalink
shutdown queue through reflection when overriding cache, related: big…
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoKiaru committed Apr 5, 2023
1 parent 85d226c commit 79713c7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/ch/epfl/biop/bdv/img/CacheControlOverride.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,28 @@
*/
package ch.epfl.biop.bdv.img;

import bdv.cache.SharedQueue;
import bdv.img.cache.VolatileGlobalCellCache;

import java.lang.reflect.Field;

public interface CacheControlOverride {

void setCacheControl(VolatileGlobalCellCache cache);

public static class Tools {
public static void shutdownCacheQueue(VolatileGlobalCellCache cache) {
try {
Field queueField = VolatileGlobalCellCache.class.getDeclaredField(
"queue");
queueField.setAccessible(true);
SharedQueue queue = (SharedQueue) queueField.get(cache);
queue.shutdown(); // Kill the non-used thread
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/ch/epfl/biop/bdv/img/OpenersImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -230,6 +231,7 @@ public void close() {

@Override
public void setCacheControl(VolatileGlobalCellCache cache) {
CacheControlOverride.Tools.shutdownCacheQueue(this.cache);
this.cache.clearCache();
this.cache = cache;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public VolatileGlobalCellCache getCacheControl() {

@Override
public void setCacheControl(VolatileGlobalCellCache cache) {
CacheControlOverride.Tools.shutdownCacheQueue(this.cache);
this.cache.clearCache();
this.cache = cache;
}
Expand Down

0 comments on commit 79713c7

Please sign in to comment.