public class SimpleThread2 implements Runnable{
private int count = 0;
public void run(){
for(int i = 0 ; i < 100 ; i++){
synchronized(this){
count += 100;
System.out.println(Thread.currentThread().getName()+":"+count);
}
//try{
// Thread.currentThread().sleep(10);
//}catch(InterruptedException e){
// e.printStackTrace();
//}
}
}
public static void main(String[] args){
SimpleThread2 t = new SimpleThread2();
Thread thread0 = new Thread(t);
Thread thread1 = new Thread(t);
thread0.start();
thread1.start();
}
}
……
……
public class SimpleThread2 implements Runnable{
private int count = 0;
public void run(){
for(int i = 0 ; i < 100 ; i++){
synchronized(this){
count += 100;
System.out.println(Thread.currentThread().getName()+":"+count);
}
try{
Thread.currentThread().sleep(10);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
public static void main(String[] args){
SimpleThread2 t = new SimpleThread2();
Thread thread0 = new Thread(t);
Thread thread1 = new Thread(t);
thread0.start();
thread1.start();
}
}
……