Module jEdit

Class ThreadUtilities

java.lang.Object
org.gjt.sp.util.ThreadUtilities

public class ThreadUtilities extends Object
The threadpool of jEdit. It uses a ExecutorService from the java.util.concurrent package. You can run Task or Runnable in it, Runnables will be encapsulated in Task and displayed in the Task Monitor.
Since:
jEdit 4.4pre1
Author:
Matthieu Casanova, Marcelo Vanzin
  • Method Details

    • runInDispatchThread

      public static void runInDispatchThread(Runnable runnable)
      Run the runnable in EventDispatch Thread. If the current thread is EventDispatch, it will run immediately otherwise it will be queued in the DispatchThread The difference with VFSManager.runInAWTThread() method is that this one will not wait for IO Request before being executed
      Parameters:
      runnable - the runnable to run - it should return something meaningful from toString() so that we can display it in the Task Monitor.
    • runInDispatchThreadAndWait

      public static void runInDispatchThreadAndWait(Runnable runnable)
      Runs the runnable in EDT through invokeLater, but returns only after the runnable is executed. This method is uninterruptible.

      Note the difference from invokeAndWait. If current thread is not EDT and there are runnables queued in EDT:

      • this method runs the runnable after them
      • invokeAndWait runs the runnable before them
      Parameters:
      runnable - the runnable to run - it should return something meaningful from toString() so that we can display it in the Task Monitor.
    • runInDispatchThreadNow

      public static void runInDispatchThreadNow(Runnable runnable)
      Runs the runnable in EDT through invokeAndWait. Even if the thread gets interrupted, the call does not return until the runnable finishes (uninterruptible method).

      This method uses EventQueue.invokeAndWait, so the following remark applies:

      If you use invokeAndWait(), make sure that the thread that calls invokeAndWait() does not hold any locks that other threads might need while the call is occurring. From the article: Threads and Swing

      Parameters:
      runnable - the runnable to run - it should return something meaningful from toString() so that we can display it in the Task Monitor.
    • runInBackground

      public static void runInBackground(Runnable runnable)
      Run the runnable in the threadpool. The runnable will be encapsulated in a Task
      Parameters:
      runnable - the runnable to run - it should return something meaningful from toString() so that we can display it in the Task Monitor.
      See Also:
    • runInBackground

      public static void runInBackground(Task task)
      Run the task in the threadpool.
      Parameters:
      task - the task to run