...
Code Block | ||
---|---|---|
| ||
class Foo implements Runnable { public void run() { // ... } public static void main(String[] args) { Foo f = new foo(); new Thread(f).run(); } } |
The start()
method is not invoked on the new thread because of the incorrect assumption that run()
activates the thread. Consequently, the statements in the run()
method execute, however, in the same thread instead of the new one.
Compliant Solution
This compliant solution correctly uses the start()
method to start a new thread which then executes the run()
method.
...