class MyThread implements Runnable { public void run() { for (int i=0;i<100;i++) { this.printMsg(); } } public void printMsg() { System.out.println(Thread.currentThread().getName()+"在运行....."); } } public class debug { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub MyThread mt=new MyThread(); Thread t =new Thread(mt); t.setName("线程A"); t.start(); for (int i=0;i<100;i++) { mt.printMsg(); } } }