Therad问题.....求助

xiaoou33 2012-08-14 11:11:38
为什么下面那个程序不输出"Main thread interrupted"这句话;路过能解释一下吗,多谢了.
class CurrentThreadDemo{
public static void main(String args[]){
Thread t = Thread.currentThread();
System.out.println("Current thread:" + t);
t.setName("My Thread");
System.out.println("After name change:" + t);
try{
for(int n=5;n>0;n--){
System.out.println(n);
Thread.sleep(1000);
}
}catch(InterruptedException e){
System.out.println("Main thread interrupted");
}
}
}
...全文
106 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
liu_su 2012-08-14
  • 打赏
  • 举报
回复
整个过程一切正常,没有受到意外中断啊。
此异常抛出的的条件:在中断状态(被任意一线程中断)时调用sleep,他不会休眠。相反,他将清除这一状态并抛出InterruptedException
lishuaibin2 2012-08-14
  • 打赏
  • 举报
回复
catch{}里面不能给答应语句
只能声明异常的类型
你应该没有弄清楚
try{}catch{throw}finally的关系

50,549

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧