Share via


Overview | Methods | This Package | All Packages

OverviewMethodsThis PackageAll Packages

Application.createThread

Executes the specified delegate on its own thread asyncronously.

Syntax

public static Thread createThread( Delegate callback )

public static Thread createThread( Delegate callback**, int** priority )

Parameters

callback

A delegate that is called as the entry point to the thread.

priority

The priority level of the thread.

Return Value

Returns a Thread object representing the new thread.

Remarks

Calling the createThread method makes it unnecessary to design a class that implements java.lang.Runnable or extends java.lang.Thread. The second version of this method allows you to define a thread priority level for the new thread. You can pass any delegate to the createThread method or use the MethodInvoker class to call a method that contains no parameters.

The following example illustrates how to use the createThread method to start a new thread within an application.

public class MyForm extends Form
{
    public MyForm()
    {
        initForm();
        //Start the thread that counts to 2000
        Application.createThread(new MethodInvoker (MyThread), Thread.NORM_PRIORITY);
    }
    
    /**This thread runs concurrently with form loading and counts to 2000*/
    private void MyThread{
        for (int i = 0; i <= 2000; i++){
            System.out.println("The value is currently equal to " + i);
        }
    }
    //More Form Code Here
}