class Synchronized {
private Synchronized() {} //1
private static int order = 0xFace; //2
public void saySomething(String name) {
System.out.print(name);
}
public static void main(String[] args) {
new Thread() {
public void run() {
order++;
this.yield(); //3
synchObj.saySomething("I am " + order + " ");
}
}.start(); //4
new Thread() {
public void run() {
++order;
this.setPriority(MAX_PRIORITY);
synchObj.saySomething("I am " + order + " ");
}
}.start(); //4
}
private static Synchronized synchObj = new Synchronized(); //5
}
Login in to like
Login in to comment