public class TestA { static int a=0; public static void main(String[] args) { ExecutorService executorService = Executors.newFixedThreadPool(10); for (int i = 0; i < 20; i++) { executorService.execute(()->{ synchronized ("锁"){ for (int j = 0; j < 10000; j++) { a++; } } }); } try { Thread.sleep(2000); System.out.println(a); } catch (InterruptedException e) { e.printStackTrace(); } } }
全部评论
(0) 回帖