package cn.thread;
/**
* 创建线程之------实现Runnable接口
* 1:创建线程类实现Runnable接口,覆盖run方法 2:使用匿名函数创建线程
*
* @author Administrator
*
*/
public class TestRunnable {
/*
* public static void main(String[] args) { MyTask myTask = new MyTask(); Thread
* t = new Thread(myTask); t.start(); }
*/
public static void main(String[] args) {
Thread thread=new Thread(new Runnable() {
@Override
public void run() {
System.out.println("当前线程:"+Thread.currentThread().getName());
}}) {
};
thread.start();
}
}
/*
* class MyTask implements Runnable{ //重写run方法 public void run() { for(int
* i=0;i<5;i++) { System.out.println("当前线程:"+Thread.currentThread().getName());
* } } }
*/