Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Thread

Hierarchy

  • Thread

Index

Constructors

constructor

  • Creates a new thread that will execute the specified function in parallel.

    Parameters

    • name: string

      an optional name for the thread

    • functionToRun: CallableFunction

      the function to be called by the thread

    Returns Thread

  • Creates a new thread that will execute the specified function in parallel.

    Parameters

    Returns Thread

Properties

Static Lock

A convenient reference to the ReentrantLock class that can be used for synchronization purposes.

Accessors

alive

  • get alive(): boolean
  • Returns whether the thread is still alive.

    Returns boolean

    true if the thread has been started but has not finished

hasReturnValue

  • get hasReturnValue(): boolean
  • Returns true if this thread has finished and did not end by throwing an uncaught exception.

    Returns boolean

    whether this thread's function returned normally

name

  • get name(): string
  • Returns the name of the thread, if any. IF the thread was not assigned a name at construction, it is given a default name.

    Returns string

    the thread name

returnValue

  • get returnValue(): boolean
  • Returns the value returned by the function passed to the thread's constructor. A function that returns no value implicitly returns undefined. If the function has not yet finished, this method returns null. If the function threw an uncaught exception, then calling this method will immediately throw that exception.

    Returns boolean

Static interrupted

  • get interrupted(): boolean
  • When called from any thread, returns true if that thread's interrupted flag has been set, then clears the flag.

    Returns boolean

Methods

interrupt

  • interrupt(): void
  • Sets the thread's interrupted flag.

    Returns void

join

  • join(timeoutInMs?: number): any
  • Cause the thread that this method is called from to wait until the thread represented by the Thread instance finishes running. If a timeout is specified, it will wait up to that long; otherwise it will wait forever.

    Parameters

    • Optional timeoutInMs: number

      the maximum time, in milliseconds, to wait for the thread

    Returns any

    the value that was returned by the function passed to the constructor (if the thread ended before the timeout elapsed)

start

  • start(): void
  • Starts executing the thread in parallel. A new operating system thread is created, and then the supplied function will be called from that thread.

    Note that a thread can only be started once. To run the same function multiple times in parallel, you must create a new thread for each run.

    Returns void

Static busyWindow

  • busyWindow(task: TaskFunction, title?: string, canCancel?: boolean): void
  • Runs a lengthy task in the background while providing feedback to the user on the progress of the task. When called, this function blocks the user interface with a status window as long as the task executes. The window displays title and status text that can be updated to reflect the state of the task, as well as a progress bar, and optionally a Cancel button. The task function is passed a single object whose properties can be updated to change the status displayed by the busy window.

    Parameters

    • task: TaskFunction

      the function to run during which the app is "busy"

    • Optional title: string

      a title for the window

    • Optional canCancel: boolean

      if true, a cancel button is shown whose status can be read from the task function

    Returns void

Static invokeAndWait

  • Calls the given function on the event dispatch (user interface) thread, waiting for it to return. If the current thread is the event dispatch thread, then it will run immediately. Otherwise, the current thread will be paused until the event dispatch thread is able to execute the function. Note that if you create a situation where the interface thread is waiting for this thread, and this thread is waiting for the interface thread, the app will deadlock.

    Parameters

    Returns any

    the result returned by the function, if any

Static invokeLater

  • Calls the given function on the event dispatch (user interface) thread at some point in the future, without waiting for it to return. For example:

    Thread.invokeLater(
        function() {
            println("I will be called later.");
        }
    );
    println("I will be called now.");

    Parameters

    • functionToRunLater: CallableFunction

      the function to invoke in the future from the interface thread

    Returns void

Static run

  • This is a convenience function that creates a new thread for the specified function and immediately starts it.

    Parameters

    Returns Thread

    the new, already-started Thread instance