Package qupath.lib.gui
Class SharedThreadPoolManager
java.lang.Object
qupath.lib.gui.SharedThreadPoolManager
- All Implemented Interfaces:
AutoCloseable
Manager to simplify submitting short tasks in background threads using a shared
ExecutorService
.
This can also create a reusable single-thread ExecutorService
using an object as a key.
- Since:
- v0.5.0 (replacing functionality previously in
QuPathGUI
- Author:
- Pete Bankhead
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Shutdown any threadpools created by this manager.static SharedThreadPoolManager
create()
Create a new instance<V> ExecutorCompletionService
<V> Create a completion service that uses a shared threadpool for the application.getSingleThreadExecutor
(Object owner) Get a reusable executor using a single thread, creating a new executor if needed.void
submitShortTask
(Runnable runnable) Submit a short task to a shared thread pool
-
Method Details
-
create
Create a new instance- Returns:
-
getSingleThreadExecutor
Get a reusable executor using a single thread, creating a new executor if needed.An owner can be specified, in which case the same Executor will be returned for the owner for so long as the Executor has not been shut down; if it has been shut down, a new Executor will be returned.
Specifying an owner is a good idea if there is a chance that any submitted tasks could block, since the same Executor will be returned for all requests that give a null owner.
The advantage of using this over creating an ExecutorService some other way is that shutdown will be called on any pools created this way whenever QuPath is quit.
- Parameters:
owner
-- Returns:
-
submitShortTask
Submit a short task to a shared thread pool- Parameters:
runnable
-
-
close
public void close()Shutdown any threadpools created by this manager.- Specified by:
close
in interfaceAutoCloseable
-