Download Designer 4.4

Transcript
204
User Manual
class Thread {
public Thread(Runnable runnable);
/** Causes this thread to begin execution and the run()
method of this thread is called and set a descriptive name
to the thread via name parameter. */
public final void start(String name);
/** Starting the thread causes the object's run() method
to be called in that separately executing thread. */
public void run();
}
Like in Java, there are two ways to create a new thread of execution in QML. One is to
declare a class to be a subclass of Thread. This subclass should override the run method of
Thread. An instance of the subclass can then be allocated and started. For example
class MyThread extends Thread {
public void run() { ... }
}
...
MyThread t = new MyThread();
t.start("MyThread");
The other way is to declare a class that implements the Runnable interface described above.
That particular class must implement the run method. An instance of the class can then be
allocated, passed as an argument when creating Thread, and started. For example
class MyThread implements Runnable {
public void run() { ... }
}
...
Thread t = new Thread(new MyThread());
t.start("MyThread");
StateMachine provides the means to construct a "state machine" — a state machine has
its own execution thread, and it supports communication with it using ports (see Section
Input and Output).