未报告的异常 java.lang.InterruptedException;必须对其进行捕捉或声明 Thread.sl
publicclassTTaimplementsRunnable{intb=100;publicsynchronizedvoidm1()throwsException{b...
public class TTa implements Runnable{
int b =100;
public synchronized void m1() throws Exception{
b = 1000;
Thread.sleep(5000);
System.out.println("b = "+b);
}
public void m2(){
System.out.println(b);
}
public void run(){
try{
m1();
} catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args){
TTa tt = new TTa();
Thread t = new Thread(tt);
t.start();
Thread.sleep(1000);
tt.m2();
}
} 展开
int b =100;
public synchronized void m1() throws Exception{
b = 1000;
Thread.sleep(5000);
System.out.println("b = "+b);
}
public void m2(){
System.out.println(b);
}
public void run(){
try{
m1();
} catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args){
TTa tt = new TTa();
Thread t = new Thread(tt);
t.start();
Thread.sleep(1000);
tt.m2();
}
} 展开
1个回答
2014-03-30
展开全部
主函数里面,会有 InterruptedException 异常,要么抛出异常、要么就catch掉
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询