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
}
Ввійдіть щоб вподобати
Ввійдіть щоб прокоментувати