会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
spring学习笔记
java例程练习(多线程[sleep()方法])
import java.util.*; public class Test { public static void main(String[] args) { MyThread thread = new MyThread(); thread.start(); try { Thread.sleep(10000);//主线程睡眠 } catch(InterruptedException e) { } thread.interrupt(); //-----------不是最好的方法 //thread.flag = false; //-----------此方法是终止线程的推荐方法 } } class MyThread extends Thread { boolean flag = true; public void run() { //每隔一秒钟打印一次时间 while(flag) { System.out.println ("====" + new Date() + "===="); try{ sleep(1000); } catch(InterruptedException e) { //----此异常必须处理 return; } } } }
posted on
2012-05-04 23:01
spring学习笔记
阅读(
235
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
导航
博客园
首页
联系
订阅
管理
公告