Class SharedThreadPoolManager

java.lang.Object
qupath.lib.gui.SharedThreadPoolManager
All Implemented Interfaces:
AutoCloseable

public class SharedThreadPoolManager extends Object implements 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 Details

    • create

      public static SharedThreadPoolManager create()
      Create a new instance
      Returns:
    • getSingleThreadExecutor

      public ExecutorService getSingleThreadExecutor(Object owner)
      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:
    • createSharedPoolCompletionService

      public <V> ExecutorCompletionService<V> createSharedPoolCompletionService(Class<V> cls)
      Create a completion service that uses a shared threadpool for the application.
      Type Parameters:
      V -
      Parameters:
      cls -
      Returns:
    • submitShortTask

      public void submitShortTask(Runnable runnable)
      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 interface AutoCloseable