Class use_HideousTask<T>

java.lang.Object
com.jackmeng.core.util.use_HideousTask<T>
All Implemented Interfaces:
impl_Identifiable, Serializable, Runnable

public final class use_HideousTask<T> extends Object implements Runnable, Serializable, impl_Identifiable
A hideous thread that kills running threads when a new task is submitted. How this task runner works:
  • Submit a task
  • The old task (if there is) is abandoned/dropped and the current submission is run. The old task does not receive any compensations.
  • The current submission runs asynchronously and outside dependent tasks waiting for the result can either wait or be alerted later for when the task is done
  • Once the current submission finishes, the task runner destroys the submission and returns to a dormant state. To force a destruction of the runner to either remove it from memory or from use, call the destroy() method.
  • At any point in time when the currentTask is finished, the result is stored in overwritable variable and can be accessed using get().
Note: run() simply tries to run the currentTask if it has not been killed yet. This object should be reused for similar tasks. THIS SHOULD NOT BE USED FOR ANY DIRECT GRAPHICS2D API RELATED OPERATIONS!!! REMEMBER JAVA SWING IS NOT THREAD SAFE.
Author:
Jack Meng
See Also:
  • Field Details

    • myName

      private final String myName
    • curr

      private transient Thread curr
    • res

      private transient T res
    • running

      private final transient AtomicBoolean running
    • currentTask

      private transient Callable<T> currentTask
  • Constructor Details

  • Method Details

    • destroy

      public void destroy()
    • shakedown

      public void shakedown()
      Resets everything in this task manager
    • is_processing

      public boolean is_processing()
    • get

      @has_Nullable public T get()
    • gentle_push

      public void gentle_push(Callable<T> task)
    • push

      public void push(Callable<T> task)
      Forcefully push the currentTask off a cliff and place the submission and make it run. No compensation for the old task's listeners and handlers: they simply will not be notified of what happened. The current task is automatically started for execution. If you do not want execution to begin right away, you may use gentle_push(Callable) which only kills and sets up the current task to be ran later.
      Parameters:
      task - The current submission
    • id

      public String id()
      Specified by:
      id in interface impl_Identifiable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • run

      public void run()
      Specified by:
      run in interface Runnable