Skip to content

Commit f96a5ed

Browse files
committed
Merge pull request #173 from scijava/executor-service
ThreadService: add API for backing ExecutorService
2 parents 6dbec39 + 6977b52 commit f96a5ed

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ public Future<?> run(final Runnable code) {
8383
return executor().submit(wrap(code));
8484
}
8585

86+
@Override
87+
public ExecutorService getExecutorService() {
88+
return executor();
89+
}
90+
91+
@Override
92+
public void setExecutorService(final ExecutorService executor) {
93+
this.executor = executor;
94+
}
95+
8696
@Override
8797
public boolean isDispatchThread() {
8898
return EventQueue.isDispatchThread();

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import java.lang.reflect.InvocationTargetException;
3535
import java.util.concurrent.Callable;
36+
import java.util.concurrent.ExecutorService;
3637
import java.util.concurrent.Future;
3738
import java.util.concurrent.ThreadFactory;
3839

@@ -91,6 +92,24 @@ public enum ThreadContext {
9192
*/
9293
Future<?> run(Runnable code);
9394

95+
/**
96+
* Gets the {@link ExecutorService} object used when {@link #run} is called.
97+
*
98+
* @return the {@link ExecutorService}, or null if an {@link ExecutorService}
99+
* is not used in this {@link ThreadService} implementation.
100+
*/
101+
ExecutorService getExecutorService();
102+
103+
/**
104+
* Sets the {@link ExecutorService} object used when {@link #run} is called.
105+
*
106+
* @param executor The {@link ExecutorService} for this {@link ThreadService}
107+
* to use internally for {@link #run} calls.
108+
* @throws UnsupportedOperationException if this {@link ThreadService} does
109+
* not use an {@link ExecutorService} to handle {@link #run} calls.
110+
*/
111+
void setExecutorService(ExecutorService executor);
112+
94113
/**
95114
* Gets whether the current thread is a dispatch thread for use with
96115
* {@link #invoke} and {@link #queue}.

0 commit comments

Comments
 (0)