Consider there are two threads,
Even Thread
- Print only Even numbers
Odd Thread
- Print only Odd numbers
Print numbers from 1 to 50 by switching Odd and Even Threads,
Approach:
step 1. Create each threads with synchronized block
step 2. Create Monitor object with shared thread status and shared number
step 3. loop through mo.number and wait or execute based on the shared thread status
...