Question: Imagine you have an ArrayList of ids(Integer). Your task is to create two threads. One thread is adding random new ids (0-100) into the

Imagine you have an ArrayList of ids(Integer). Your task is to create

Imagine you have an ArrayList of ids(Integer). Your task is to create two threads. One thread is adding random new ids (0-100) into the list every one second. The second thread is keeping the list sorted in descending order and printing the list on the screen every two 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. [ ] [78] [93,80] [80, 77, 38] [77, 38, 16,51] [38, 16, 51, 75, 10] [16, 51, 75, 10, 81, 10] [51, 75, 10, 81, 10, 60, 1] [75, 10, 81, 10, 60, 1, 71, 6] [10, 81, 10, 60, 1, 71, 6, 14, 81]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!