Module ojalgo

Class ProcessAwareThread

  • All Implemented Interfaces:
    java.lang.Runnable

    final class ProcessAwareThread
    extends java.lang.Thread
    A daemon thread that can be bound to an external Process. When this thread is interrupted, it will attempt to forcibly terminate the bound process before delegating to Thread.interrupt().

    Typical usage:

     Thread t = DaemonPoolExecutor.newProcessAwareThreadFactory("ojAlgo-proc").newThread(() -> {
         Process p = new ProcessBuilder("sleep", "10").start();
         if (Thread.currentThread() instanceof ProcessAwareThread pat) pat.setProcess(p);
         p.waitFor();
     });
     t.start();
     // later...
     t.interrupt(); // will destroy the process
     
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.atomic.AtomicReference<java.lang.Process> myReference  
      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      ProcessAwareThread​(java.lang.ThreadGroup group, java.lang.Runnable target, java.lang.String name)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void interrupt()  
      (package private) void setProcess​(java.lang.Process process)  
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • myReference

        private final java.util.concurrent.atomic.AtomicReference<java.lang.Process> myReference
    • Constructor Detail

      • ProcessAwareThread

        ProcessAwareThread​(java.lang.ThreadGroup group,
                           java.lang.Runnable target,
                           java.lang.String name)
    • Method Detail

      • interrupt

        public void interrupt()
        Overrides:
        interrupt in class java.lang.Thread
      • setProcess

        void setProcess​(java.lang.Process process)