Class ThreadCollection

java.lang.Object
com.seeq.link.sdk.utilities.ThreadCollection

public class ThreadCollection extends Object
A facility that manages a collection of background threads that need to be spawned and potentially all interrupted in a controlled way.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    The count of all background threads being managed by this collection.
    An identifier used in log output for this object.
    void
    interrupt(long requestId)
    Interrupt a request, given the identifier supplied when the request was created.
    protected boolean
     
    void
    An identifier used in log output for this object.
    void
    Shuts down all threads being managed in this collection and does not return until they are verified to have died.
    spawn(Runnable callback)
    Spawns a thread that executes the supplied callback.
    spawn(Runnable callback, int priority)
    Spawns a thread that executes the supplied callback.
    spawn(Runnable callback, long timeoutMillis, long requestId)
    Spawns a thread that executes the supplied callback.
    spawn(Runnable callback, long timeoutMillis, long requestId, int priority)
    Spawns a thread that executes the supplied callback.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ThreadCollection

      public ThreadCollection()
    • ThreadCollection

      public ThreadCollection(String id)
  • Method Details

    • getID

      public String getID()
      An identifier used in log output for this object.
      Returns:
      an identifier used in log output for this object
    • setID

      public void setID(String id)
      An identifier used in log output for this object.
      Parameters:
      id - an identifier used in log output for this object
    • spawn

      public Thread spawn(Runnable callback)
      Spawns a thread that executes the supplied callback.
      Parameters:
      callback - The callback that represents the task to be performed
      Returns:
      the Thread object that was spawned
    • spawn

      public Thread spawn(Runnable callback, int priority)
      Spawns a thread that executes the supplied callback.
      Parameters:
      callback - The callback that represents the task to be performed
      priority - The desired thread priority; see Thread.setPriority(int)
      Returns:
      the Thread object that was spawned
    • spawn

      public Thread spawn(Runnable callback, long timeoutMillis, long requestId)
      Spawns a thread that executes the supplied callback.
      Parameters:
      callback - The callback that represents the task to be performed
      timeoutMillis - How long the request remains valid. After timeoutMillis milliseconds, the request should be interrupted, to free up resources for future requests.
      requestId - An identifier for the request which must be greater than or equal to 0 and unique to the connection. This ID allows for subsequent cancellation messages to be associated with the same request.
      Returns:
      the Thread object that was spawned
    • spawn

      public Thread spawn(Runnable callback, long timeoutMillis, long requestId, int priority)
      Spawns a thread that executes the supplied callback.
      Parameters:
      callback - The callback that represents the task to be performed
      timeoutMillis - How long the request remains valid. After timeoutMillis milliseconds, the request should be interrupted, to free up resources for future requests.
      requestId - An identifier for the request which must be greater than or equal to 0 and unique to the connection. This ID allows for subsequent cancellation messages to be associated with the same request.
      priority - The desired thread priority; see Thread.setPriority(int)
      Returns:
      the Thread object that was spawned
    • interrupt

      public void interrupt(long requestId)
      Interrupt a request, given the identifier supplied when the request was created. Note: interrupting a request does not mean it will terminate immediately, or at all. It only means that the interrupted flag will be set on the thread. Some connectors will watch for this flag and terminate the request, but others may not.
      Parameters:
      requestId - the identifier supplied when the request was created
    • shutDownAll

      public void shutDownAll()
      Shuts down all threads being managed in this collection and does not return until they are verified to have died.
    • getCount

      public int getCount()
      The count of all background threads being managed by this collection.
      Returns:
      the count of all background threads
    • isShutdown

      protected boolean isShutdown()