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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started