//创建线程:实现Runnable接口 public class MyThread implements Runnable { public void run(){ for (int i = 1; i<=100; i++){ System.out.println(Thread.currentThread().getName()+":"+i); } } }
测试类
//测试线程 public class TestThread2 { public static void main(String[] args) { //创建线程对象 Runnable runnable = new MyThread(); Thread thread = new Thread(runnable,"Mythread1"); Thread thread2 = new Thread(runnable,"Mythread2"); //启动线程 thread.start(); thread2.start(); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)