All pastes #266945 Raw Edit

Miscellany

public java v1 · immutable
·published 2006-12-04 14:52 UTC
rendered paste body
public class lol {    public static void main(String[] args) {        demo2();    }    public static void demo1() {        final Object lock = new Object();        Thread a = new Thread(new Runnable() {            public void run() {                synchronized (lock) {                    try {                        lock.wait();                    } catch (InterruptedException e) {                    }                    System.out.println("A");                }            }        });        Thread b = new Thread(new Runnable() {            public void run() {                synchronized (lock) {                    lock.notify();                    System.out.println("B");                }            }        });        a.start();        b.start();    }    public static void demo2() {        final Object lock = new Object();        Thread a = new Thread(new Runnable() {            public void run() {                synchronized (lock) {                    try {                        lock.wait();                    } catch (InterruptedException e) {                    }                    System.out.println("A");                }            }        });        a.start();        synchronized (lock) {            lock.notify();            System.out.println("B");        }    }}