Package jadex.future

Class ThreadSuspendable

All Implemented Interfaces:
ISuspendable

public class ThreadSuspendable extends ThreadLocalTransferHelper implements ISuspendable
Suspendable for threads.
  • Field Details

    • WAITING_THREADS

      public static final Map<Thread,Future<?>> WAITING_THREADS
      Threads waiting due to thread suspendable.
    • future

      protected IFuture<?> future
      The future.
    • resumed

      protected boolean resumed
      The resumed flag to differentiate from timeout.
    • lock

      protected ReentrantLock lock
      Use reentrant lock/condition instead of synchronized/wait/notify to avoid pinning when using virtual threads.
    • wait

      protected Condition wait
  • Constructor Details

    • ThreadSuspendable

      public ThreadSuspendable()
  • Method Details

    • suspend

      public void suspend(Future<?> future, long timeout, boolean realtime)
      Suspend the execution of the suspendable.
      Specified by:
      suspend in interface ISuspendable
      Parameters:
      future - The future to wait for.
      timeout - The timeout.
      realtime - Flag if timeout is realtime (in contrast to simulation time).
    • resume

      public void resume(Future<?> future)
      Resume the execution of the suspendable.
      Specified by:
      resume in interface ISuspendable
      Parameters:
      future - The future that issues the resume.
    • getLock

      public ReentrantLock getLock()
      Return the lock for internal synchronization.
      Specified by:
      getLock in interface ISuspendable
    • getFuture

      public IFuture<?> getFuture()
      Get the future if currently suspended, null otherwise.
      Specified by:
      getFuture in interface ISuspendable
    • getDefaultTimeout

      protected long getDefaultTimeout()
      Get the default timeout.
      Returns:
      The default timeout (-1 for none).