try this ..you will get 000000 as output
public class ThreadClass extends Thread{
public ThreadClass(int x){
this.x=x;
}
static
String s="";
static volatile int x=0;
public static void doVIP(){
s=s+x;
try{
Thread.sleep(10);
System.out.print(s);
}catch(Exception e){
//s=s+x;
}
}
public void run(){
synchronized(s){
doVIP();
}
}
public static void doDelay(long g){
try{Thread.sleep(g);}catch(Exception e){}
}
public static void main(String args[]){
ThreadClass tc1=new ThreadClass(2);
ThreadClass tc2=new ThreadClass(1);
ThreadClass tc3=new ThreadClass(0);
tc1.start(); doDelay(100);
tc2.start(); doDelay(100);
tc3.start(); doDelay(100);
}
}