Waiting on an object : Wait « Threads « Java

Waiting on an object

public class Main {
  public static void main(String str[]) {
    final Object monitor = new Object();
    new Thread() {
      public void run() {
        try {
          synchronized (monitor) {
            System.out.println("10 seconds ...");
            System.out.println("Wait over");
        } catch (Throwable t) {


Related examples in the same category

1.Wait the for the completion of a thread
2.Wait for the threads to finish
3.Demonstrate join().
4.A simple demonstration of wait() and notify().
5.Suspend, resume, and stop a thread.
6.Launch many programs using Thread and use join() to wait for the completion.