最近在学习多线程,刚入门,好多东西不懂,下面这段代码今天想了半天也没明白,希望看到的兄弟姐妹能解释下。
public class NotThreadSafeCounter extends Thread { private static int counter = 0; public void run() { System.out.println("counter:" + getCount()); } public static int getCount() { try { Thread.sleep(1500); } catch (Exception e) { e.printStackTrace(); } return counter++; } public static void main(String[] args) { for (int i = 0; i < 5; i++) { new NotThreadSafeCounter().start(); } } }