I want to run this asynchronously but all no thread locking , no syncronization also awaitTermination timeout should not be increased.
@Test
void arrayCheck() throws InterruptedException {
final int[] count = {0};
ExecutorService executorService = Executors.newFixedThreadPool(5);
for (int i = 0; i <10000; i++) {
executorService.execute(() ->
{
try {
Thread.sleep(100);
count[0]++;
System.out.println(Thread.currentThread().getName()+"----"+count[0]+"---");
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
executorService.awaitTermination(10,TimeUnit.MILLISECONDS);
}
Assertions.assertEquals(10000,count[0]);
}
i have used atomic variables but i have to use array only