Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Thread.start() method starts executing a thread's run() method in that thread. It is a mistake to directly invoke the run() method on a Thread object. When invoked directly, the statements in the run() method execute in the current thread instead of the newly created thread. Furthermore, if the Thread object is not constructed from a Runnable object but rather by instantiating a subclass of Thread that does not override the run() method, then a call to the subclass's run() method invokes Thread.run() which performs a no-operation.

...

This compliant solution correctly uses the start() method to start a new thread which then executes . The start() method internally invokes the run() method in the new thread.

Code Block
bgColor#ccccff
final class Foo implements Runnable {
  public void run() {
    // ...
  }
  
  public static void main(String[] args) {
    Foo f = new foo();
    new Thread(f).start();
  }
}

...