runnable 接口
线程创建类
Thread() 其中的参数会有不同;
线程的方法:
void start();--启动线程
static void sleep(); --线程休眠
void join() ; --使其他线程等待当前线程终止
void static yeild() 当前运行线程释放处理器资源
获取线程的引用 :static Thread currentThread() 返回当前运行的线程引用。
示列代码: import static java.lang.Thread.sleep; public class Actor extends Thread { public void run(){ System.out.println(getName()+"是一个演员"); int count=0; boolean keepRunning =true; while (keepRunning) { System.out.println(getName() + "登台演出:" + (++count)); if (count ==50){ keepRunning=false; } if(count%10==0){ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } System.out.println(getName()+"演出结束"); } public static void main(String[] args) { Thread actor =new Actor(); actor.setName("Mr.Thread"); actor.start(); } }