private static AtomicInteger TOTAL_COUNT = new AtomicInteger(0);
@Test
public void testThread(){
ExecutorService executorService = Executors.newFixedThreadPool(2);
executorService.execute(new Runnable() {
@Override
public void run() {
while(TOTAL_COUNT.intValue() < 100) {
if (TOTAL_COUNT.intValue() % 2 == 0) {
System.out.println("ThreadA:" + TOTAL_COUNT.incrementAndGet());
}
}
}
});
executorService.execute(new Runnable() {
@Override
public void run() {
while(TOTAL_COUNT.intValue() < 100) {
if (TOTAL_COUNT.intValue() % 2 == 1) {
System.out.println("ThreadB:" + TOTAL_COUNT.incrementAndGet());
}
}
}
});
executorService.shutdown();
}