Question: JAVA Programming questions Imagine you have a static ArrayList that contains a list of numbers(Integer). Your task is to create two threads. One thread is
JAVA Programming questions
Imagine you have a static ArrayList that contains a list of numbers(Integer). Your task is to create two threads. One thread is adding random new numbers(1~100) into the list every 1 second. The second thread is removing all the odd numbers, and printing the list on the screen every 1.5 seconds.
Your program should never end and please make sure to handle any race condition to avoid the ConcurrentModificationException.
Please check below for a sample output.
[] [] [48] [48] [48, 2] [48, 2, 8] [48, 2, 8, 80, 90] [48, 2, 8, 80, 90] [48, 2, 8, 80, 90, 94] [48, 2, 8, 80, 90, 94, 28] [48, 2, 8, 80, 90, 94, 28, 80] [48, 2, 8, 80, 90, 94, 28, 80, 40]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
