I have a Threadpool, please see the code below. What I want now is that before the asserEquals statement it is waited until all jobs finished. How can this be achieved? awaitTermination() only works if shutdown is already called but that is not what I want.
private volatile int i = 0;
@Test
public void threadPoolTest() throws InterruptedException {
ExecutorService threadPool = Executors.newFixedThreadPool(8);
threadPool.submit(new Runnable() {
public void run() {
i++;
}
});
threadPool.submit(new Runnable() {
public void run() {
i++;
}
});
assertEquals(2,i);
threadPool .shutdown();
}