日期:2014-05-20 浏览次数:20681 次
public class test {
/**
* @param args
*/
public static int i = 100;
public static void main(String[] args) {
testThread t1 = new testThread(1);
testThread t2 = new testThread(1);
testThread t3 = new testThread(0);
testThread t4 = new testThread(0);
new Thread(t1).start();
new Thread(t2).start();
new Thread(t3).start();
new Thread(t4).start();
}
}
class testThread implements Runnable{
private int j;
public testThread(int j){
this.j=j;
}
public testThread(){}
public void run(){
int count = 50;
while(count>0){
if(j==1){
//add();
System.out.println("当前线程:"+Thread.currentThread().getName()+"增加票数至"+(++test.i)+"张");
}else if(j==0){
System.out.println("当前线程:"+Thread.currentThread().getName()+"减少票数至"+(--test.i)+"张");
//modfiy();
}
count--;
}
}
/*public synchronized void add(){
System.out.println("当前线程:"+Thread.currentThread().getName()+"增加票数至"+(++test.i)+"张");
}
public synchronized void modfiy(){
Syste*/
}