实现Runnable接口方式创建线程

public class MyRunnable implements Runnable
{
int a=0;
public void run(){
for(a=0;a<10;a++){
try{Thread.sleep(100);}catch(Exception e){}
System.out.println(Thread.currentThread().getName()+":"+a);
}
}
public static void main(String[] args)
{
MyRunnable mr=new MyRunnable();
Thread t1=new Thread(mr);
Thread t2=new Thread(mr);
t1.start();
t2.start();
}
}
posted @ 2012-03-19 12:26  haiwei.sun  阅读(144)  评论(0编辑  收藏  举报
返回顶部