Jay,
I checked the fallowing code both on Unix and Linux, and I got ONLY false to the output!!!; it
remains only the Windows platform, but if the output it's different I should change my motto to "Programm once, run everywhere. NEVER bet on it!"
Just joking, here is the code:
-----------------------------------------------
public class SyncTest implements Runnable{
private int x;
private int y;
private synchronized void setX(int i){x=i;}
private synchronized void setY(int i){y=i;}
public void setXY(int i){
setX(i);
//try{
// Thread.sleep(100);
//}catch(Exception e){}
setY(i);
}
public synchronized boolean check(){
return x!=y;
}
public void run(){
for(int i=0;i<100;i++){
setXY(i);
System.out.println(x+","+y+","+check());
}
}
public static void main(
String[] args){
SyncTest t = new SyncTest();
Thread[] ts = new Thread[10];
for(int i=0;i<ts.length;i++){
ts[i]=new Thread(t);
ts[i].start();
String ourThreads = ts.toString();
System.out.println("< " + ourThreads + " >");
}
}
}
-----------------------------------------------
Did you tried to comment out the sleep() and run it?
Thanx,
Michael