Menu

class: threadState

[20:6] static extends: object

Defines the possible states of a thread.

Members

  • stNew
  • stRunnable
  • stBlocked
  • stWaiting
  • stTimedWaiting
  • stTerminated

class: Thread

[34:14] (extern: com.aussom.stdlib.AThread) extends: object

The Thread class provides cooperative multithreading support in the browser via TeaVM coroutines. Extend this class and override run() to define thread behavior, then call start() to begin execution.

Methods

  • setOnRun (callback Callback)

    Sets the callback function to invoke when the thread starts.

    • @p Callback The callback to run.
    • @r this object
  • startThread ()

    Starts the underlying Java thread. Called by start().

    • @r this object
  • sleep (int MillsToWait = 0)

    Suspends the thread for the specified number of milliseconds.

    • @p MillsToWait Milliseconds to sleep (default 0).
    • @r this object
  • interrupt ()

    Interrupts this thread.

    • @r this object
  • setPriority (int Priority = 5)

    Sets the thread priority (1-10, default 5).

    • @p Priority The priority value.
    • @r this object
  • setName (string Name)

    Sets the thread name.

    • @p Name The name to assign.
    • @r this object
  • setDaemon (bool SetDaemon = true)

    Sets whether this thread is a daemon thread.

    • @p SetDaemon True to make daemon (default true).
    • @r this object
  • start (callback OnRun = null)

    Starts the thread. If no callback has been set via setOnRun(), this method automatically assigns run() as the callback before starting.

    • @p OnRun is an optinal callback to run on thread start.
    • @r this object
  • isInterrupted ()

    Returns true if this thread has been interrupted.

  • isAlive ()

    Returns true if this thread is still alive.

  • getPriority ()

    Returns the thread priority.

  • join (int MillsToWait = 0)

    Waits for this thread to finish. Optionally waits up to MillsToWait ms.

    • @p MillsToWait Max milliseconds to wait (default 0 = wait forever).
    • @r this object
  • isDaemon ()

    Returns true if this thread is a daemon thread.

  • toString ()

    Returns a string representation of this thread.

  • getId ()

    Returns the thread's unique ID.

  • getThreadState ()

    Returns the current state of this thread as a threadState enum value.

  • getOnRun ()

    Returns the currently set run callback, or null if none is set.

class: Timer

[149:14] (extern: com.aussom.stdlib.ATimer) extends: object

The timer class provides one-shot and repeating timer functionality. Under the hood, TeaVM maps java.util.Timer to browser setTimeout calls.

Methods

  • Timer (int TimeMills, callback OnTimeOut)

    Creates a new timer.

    • @p TimeMills Duration in milliseconds.
    • @p OnTimeOut Callback to invoke when the timer fires.
  • newTimer (int TimeMills, callback OnTimeOut)

  • start ()

    Starts the timer for a single one-shot firing after the configured duration.

  • startInterval ()

    Starts the timer to fire repeatedly at the configured interval.

  • stop ()

    Stops the timer and cancels any pending firings.

  • restart ()

    Restarts the timer from the beginning with the current duration.

  • setDuration (int TimeMills)

    Sets the timer duration in milliseconds.

    • @p TimeMills New duration.
  • getDuration ()

    Returns the current timer duration in milliseconds.