Runnable interface


Thread class
implements the Runnable interface


Two ways to create a new thread


synchronized
A synchronized instance method (i.e. public synchronized int fooBar() {...}) or a synchronized block (i.e. synchronized(obj) {...}) blocks until the mutex of the object is acquired.
A synchronized class method (i.e. public synchronized static int fooBar() {...}) blocks until the mutex of the Class object corresponding to the class is acquired.

wait()/notify()
These methods are methods of the Object class,
They must be called from a block or method where the object is synchronized

notifyAll must be used when example:
in some part of the code
synchronized (lock) {
   while (lock.getLock()) {
       try {
           lock.wait();
       } catch (Exception e) {}
   }
}
somewhere else
synchronized (lock) {
    someComputation();
    lock.notify();
}



Last update: July 26th, 2003 - Laurent