public class MultiThread { public static void main(String[] args) { Thread t1 = new Thread(new ThreadDemo("线程1")); Thread t2 = new Thread(new ThreadDemo("线程2")); t1.start(); t2.start(); } } class ThreadDemo implements Runnable { private String name; public ThreadDemo(String name) { this.name = name; } @Override public void run() { for (int i = 0; i < 5; i++) { System.out.println("线程 :" + name + "开始干活"); try { //休息1秒模拟干活 Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }