Skip to content

Commit a94f114

Browse files
committed
ThreadService: track parent threads globally
At a given time, each Thread can only have one parent Thread, even if there are multiple application Contexts in play each with its own ThreadService. Without this change, the new getThreadContext method will sometimes fail to return ThreadContext.OTHER as expected, because thread parents were only tracked by the spawning ThreadService, and hence unavailable to the other ThreadService doing the interrogation.
1 parent 0da9121 commit a94f114

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/main/java/org/scijava/thread/DefaultThreadService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public final class DefaultThreadService extends AbstractService implements
5757

5858
private static final String SCIJAVA_THREAD_PREFIX = "SciJava-";
5959

60+
private static WeakHashMap<Thread, Thread> parents =
61+
new WeakHashMap<Thread, Thread>();
62+
6063
@Parameter
6164
private LogService log;
6265

@@ -66,8 +69,6 @@ public final class DefaultThreadService extends AbstractService implements
6669

6770
private boolean disposed;
6871

69-
private WeakHashMap<Thread, Thread> parents = new WeakHashMap<Thread, Thread>();
70-
7172
// -- ThreadService methods --
7273

7374
@Override

0 commit comments

Comments
 (0)