`
zhouyu260
  • 浏览: 10116 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

实现Runnable接口

    博客分类:
  • j2se
阅读更多
public class Test2 {

	public static void main(String[] args) {
		MyRunnable mr = new MyRunnable();
		Thread t = new Thread(mr);
		//启动
		t.start();
		try {
			for (int i = 0; i < 10; i++) {
				Thread.sleep(1000);
				System.out.println("main:"+i);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
public class MyRunnable implements Runnable{

	public void run() {
		try {
			for (int i = 0; i < 10; i++) {
				Thread.sleep(1000);
				System.out.println("run:"+i);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics