...
This noncompliant code example explicitly invokes run()
in the context of the current thread.
Code Block | ||
---|---|---|
| ||
public final class Foo implements Runnable {
public void run() {
// ...
}
public static void main(String[] args) {
Foo f = new foo();
new Thread(f).run();
}
}
|
...
This compliant solution correctly uses the start()
method to start a new thread. The start()
method internally invokes the run()
method in the new thread.
Code Block | ||
---|---|---|
| ||
public final class Foo implements Runnable {
public void run() {
// ...
}
public static void main(String[] args) {
Foo f = new foo();
new Thread(f).start();
}
}
|
...