在學習并發(fā)。嘗試做一個計數器。然后不知道為什么有時候計數會多1.有時候又不會。請問要怎樣才能完成正確的計數。publicclassIncrementTest{staticclassCounter{privateAtomicIntegercount=newAtomicInteger();publicvoidincrement(){count.incrementAndGet();}publicintgetCount(){returncount.get();}}staticCounterc=newCounter();staticclassTestimplementsRunnable{publicvoidrun(){while(c.getCount()
Java并發(fā)計數器多1
陪伴而非守候
2019-05-25 17:08:47