...
| Code Block | ||
|---|---|---|
| ||
class ThreadStarter implements Runnable {
Thread thread;
public ThreadStarter() {
thread = new Thread(this);
}
public void startThread() {
thread.start();
}
public void run() {
// thread execution code...
}
}
|
It is safe to create the thread in the constructor as long as it is not started until object construction is over.
...