public class VolatileT {
private int number = 0;
public int getNumber(){
return this.number;
}
public void increase(){
synchronized(this){
this.number++;
}
}
public static void main(String[] arg){
final VolatileT vo = new VolatileT();
for(int i=0;i<500;i++){
new Thread(new Runnable(){
@Override
public void run() {
vo.increase();
}
}).start();
//System.out.println(vo.getNumber());
System.out.println(Thread.activeCount());
}
if(Thread.activeCount()>1){
Thread.yield();
}
System.out.println("result="+ vo.getNumber());
}
}