class Thread

A thread object allowing for multi-threaded scripts within the ferite environment

Description

This class provides the basic framework for threading. To create a thread you have to inherit from this base class and create a run method. Once that is done You create an instance of the object and call the .start() method NOT the .run() method. This causes a thread to be spawned and the .run() method called. The thread will exit when the .run() method has completed. If you implement your own constructor is is VITAL that you call super() to make sure that the native side of the thread is instantiated correctly.

Example

class MyThread extends Thread {
    function run() {
        while( true ) {
            Thread.sleep( 1000 );
            Console.println( "Another Second Gone" );
        }
    }    
}

object thread = new MyThread();
thread.start( true );

class contents [NB. Highlighted attributes are static members]
Functions
function constructor() - The constructor
function isRunning() - Check to see if the thread is running
function join(object) - Cause the calling thread to wait for the thread passed to the method to complete
function run() - The function that gets run. The stock run method exits immediatly. You need to implement your own function.
function setPassExceptions(number) - Set whether or not exceptions within a thread are passed onto the main process when the thread finishes executing.
function sleep(number) - Causes the thread to sleep for an amount of time
function start() - Start the thread of execution
function start(number) - Start the thread of execution

Functions

function constructor Click to go up to the list
The constructor
Warning!
You must make sure this is called within sub-classes.
Declaration:
    function constructor()

function isRunning Click to go up to the list
Check to see if the thread is running
Declaration:
    function isRunning()
Returns:
    true if it is running, false otherwise

static function join Click to go up to the list
Cause the calling thread to wait for the thread passed to the method to complete
Declaration:
    static native function join( object thread )
Parameters:
    Parameter #1: object thread - The thread to wait for
Example:

class MyThread extends Thread {
    function run() {
        while( true ) {
            Thread.sleep( 1000 );
            Console.println( "Another Second Gone" );
        }
    }    
}

object thread = new MyThread();
thread.start(false);
Thread.join(thread);


function run Click to go up to the list
The function that gets run. The stock run method exits immediatly. You need to implement your own function.
Declaration:
    function run()

function setPassExceptions Click to go up to the list
Set whether or not exceptions within a thread are passed onto the main process when the thread finishes executing.
Declaration:
    function setPassExceptions( number value )
Description:
If an exception is thrown within a thread, only that thread will suffer the exception. If you pass true to the function, when a thread has an exception it will pass it onto the main program thread.
Parameters:
    Parameter #1: number value - Either true or false

function sleep Click to go up to the list
Causes the thread to sleep for an amount of time
Declaration:
    function sleep( number msecs )
Parameters:
    Parameter #1: number msecs - The amount of time to sleep in microseconds

function start Click to go up to the list
Start the thread of execution
Declaration:
    function start()
Description:
When this function is run, it will return straight away. The thread will clean itself up when done.

function start Click to go up to the list
Start the thread of execution
Declaration:
    function start( number detach )
Description:
When this function is run, it will return straight away. Pass true if you want the Thread to automatically clear itself up. Otherwise Thread.join() must be called on it.
Parameters:
    Parameter #1: number detach - 'true' or 'false', if 'true' the thread will detach upon running

Automatically generated at 12:08PM, Wednesday 25 May 2005 by feritedoc.