多线程的问题
public class ex_11_3_1 implements Runnable
{
public int x;
public static void main(String args[]){
ex_21_4 test=new ex_21_4();
Thread t1=new Thread(test);
Thread t2=new Thread(test);
t1.start();
t2.start();
}
public void run(){
int temp;
while(true){
temp=x+1;
try{
Thread.sleep(1000);
}
catch(InterruptedException e)
{}
x=temp;
System.out.println("线程"+Thread.currentThread().getName()+"中的x的值为"+x);
}
}
};
这是我按照书上写的代码。但是我总是编译不通。
问题1,ex_21_4方法我为什么没有找到呢?
问题2,是不是与线程有关的时候,必须使用public void run()?
问题3,while(true){}我想问一下,这个是个什么结构啊。
问题4,catch(InterrupttedException e)这里的InterruptedException 是什么意思呢?