Class EasyThread

java.lang.Object
com.codename1.util.EasyThread

public final class EasyThread extends Object
An easy API for working with threads similar to call serially/and wait that allows us to create a thread and dispatch tasks to it.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Callback listener for errors on easy thread
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a callback for error events, notice that this code isn't thread safe and should be invoked synchronously.
    static void
    Adds a callback for error events, notice that this code isn't thread safe and should be invoked synchronously.
    boolean
    Returns true if the current thread is the easy thread and false othewise similar to the isEDT method
    void
    Stops the thread once the current task completes
    void
    Removes a callback for error events, notice that this code isn't thread safe and should be invoked synchronously.
    static void
    Removes a callback for error events, notice that this code isn't thread safe and should be invoked synchronously.
    <T> void
    Runs the given object asynchronously on the thread and returns the result object
    <T> T
    Runs the given runnable on the thread and blocks until it completes, returns the value object
    void
    Runs the given runnable on the thread, the method returns immediately
    void
    Invokes the given runnable on the thread and waits for its execution to complete
    void
    setPriority(int newPriority)
    Changes the priority of this EasyThread.
    static EasyThread
    start(String name)
    Starts a new thread

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
     
    boolean
    Indicates whether some other object is "equal to" this one.
    final Class
    Returns the runtime class of an object.
    int
    Returns a hash code value for the object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes current thread to wait until another thread invokes the method or the method for this object.
    final void
    wait(long timeout)
    Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
    final void
    wait(long timeout, int nanos)
    Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
  • Method Details

    • start

      public static EasyThread start(String name)

      Starts a new thread

      Parameters
      • name: the display name for the thread
      Returns

      a new thread instance

    • addGlobalErrorListener

      public static void addGlobalErrorListener(EasyThread.ErrorListener err)

      Adds a callback for error events, notice that this code isn't thread safe and should be invoked synchronously. This method must never be invoked from within the resulting callback code!

      Parameters
      • err: the error callback
    • removeGlobalErrorListener

      public static void removeGlobalErrorListener(EasyThread.ErrorListener err)

      Removes a callback for error events, notice that this code isn't thread safe and should be invoked synchronously. This method must never be invoked from within the resulting callback code!

      Parameters
      • err: the error callback
    • run

      public <T> void run(RunnableWithResult<T> r, SuccessCallback<T> t)

      Runs the given object asynchronously on the thread and returns the result object

      Parameters
      • r: runs this method

      • t: object is passed to the success callback

    • run

      public void run(Runnable r)

      Runs the given runnable on the thread, the method returns immediately

      Parameters
      • r: the runnable
    • run

      public <T> T run(RunnableWithResultSync<T> r)

      Runs the given runnable on the thread and blocks until it completes, returns the value object

      Parameters
      • r: the runnable with result that will execute on the thread
      Returns

      value returned by r

    • runAndWait

      public void runAndWait(Runnable r)

      Invokes the given runnable on the thread and waits for its execution to complete

      Parameters
      • r: the runnable
    • kill

      public void kill()
      Stops the thread once the current task completes
    • isThisIt

      public boolean isThisIt()

      Returns true if the current thread is the easy thread and false othewise similar to the isEDT method

      Returns

      true if we are currently within this easy thread

    • addErrorListener

      public void addErrorListener(EasyThread.ErrorListener err)

      Adds a callback for error events, notice that this code isn't thread safe and should be invoked synchronously. This method must never be invoked from within the resulting callback code!

      Parameters
      • err: the error callback
    • removeErrorListener

      public void removeErrorListener(EasyThread.ErrorListener err)

      Removes a callback for error events, notice that this code isn't thread safe and should be invoked synchronously. This method must never be invoked from within the resulting callback code!

      Parameters
      • err: the error callback
    • setPriority

      public void setPriority(int newPriority)

      Changes the priority of this EasyThread.

      Parameters
      • newPriority: priority to set this thread to