日期:2014-05-20 浏览次数:20781 次
class Wrapper {
int val=0;
}
public class t{
public static void main(String[]args) throws InterruptedException{
for (int q= 0;q<30;q++){
Thread t = new Thread (new tRunnable());
t.start();
}
}
}
class tRunnable implements Runnable {
static Wrapper self = new Wrapper();
public void run(){
set1();
}
public synchronized void set1(){
for (int i = 1;i<50;i++)
{self.val = i;
System.out.println(self.val);
}
System.out.println("Finished!!!!!!!!!!!!!");
}
}
public static void main(String[]args) throws InterruptedException{
tRunnable tr=new tRunnable();//产生一个Runnable对象。
for (int q= 0;q<30;q++){
Thread t = new Thread (tr);//多个线程公用一个Runnable对象。
t.start();