创建线程的两种方式

来源:互联网 发布:直播网络公会 编辑:程序博客网 时间:2024/05/17 00:51
package cn.cblue.heima2;


import java.util.Date;


/**
 * @Description: 创建线程的两种方式
 * @author huangzjb cblue2013@126.com
 * @Company Digital China
 * @date 2014-5-28 下午04:16:40
 * @version 1.0
 */


public class TraditionalThread {
public static void main(String[] args) {


// 第一种:继承Thread类
new Thread() {
public void run() {


}
}.start();


// 第二种:实现Runnable接口


new Thread(new Runnable() {
public void run() {
System.out.println(Thread.currentThread().getName());
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(new Date().getSeconds());
}
}
}).start();
}


}

0 0
原创粉丝点击