// 定义线程 class Machine extends Thread { private String name; private Thread thread; Machine(String name) { this.name = name; } public void run() { System.out.println("机器" + name + "开始运行"); try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("机器" + name + "结束运行"); } public void start() { System.out.println("机器" + name + "启动了"); if (thread == null) { thread = new Thread(this, name); thread.start(); } } } // 调用线程 Machine m1 = new Machine("机器1"); Machine m2 = new Machine("机器2"); Machine m3 = new Machine("机器3"); m1.start(); m2.start(); m3.start();