写个简单的例子
public class TestThread implements Runnable { public static int count = 0; @Override public void run() { for (int i = 0; i < 100_0000; i++) { count ++; } System.out.println("end..."); } public static void main(String[] args) throws InterruptedException { Runnable runnable = new TestThread(); for (int i = 0; i < 10; i++) { Thread thread = new Thread(runnable); thread.start(); } Thread.sleep(60000); System.out.println(TestThread.count); } }
看输出结果
end... end... end... end... end... end... end... end... end... end... 8660986