In Java multithreading environment, one thread can send an interrupt to another by calling the interrupt() method on the Thread object for the target thread (i.e., the thread to be interrupted). To handle interrupts in a target thread, Java allows two approaches. One is performed by writing an exception handler for InterruptedException (only applicable if the target thread is invoking methods which throw that exception such as sleep). The other approach is performed by periodically checking the interrupt status flag Thread.interrupted and performing the handling routine when that flag is set to true. Write a Java program that illustrates the use of the two approaches described above. Your program should start by creating two threads, each thread should use different interrupt handling approach. Then, the program needs to send interrupts to each one of the created threads such that a thread needs to return (i.e., stop execution) after receiving an interrupt from the main thread. Make sure to output (print out) the status of each thread before and after being interrupted.
Part 3: Interrupt handling (30%)
In Java multithreading environment, one thread can send an interrupt to another by calling the
interrupt() method on the Thread object for the target thread (i.e., the thread to be
interrupted). To handle interrupts in a target thread, Java allows two approaches. One is performed
by writing an exception handler for InterruptedException (only applicable if the target
thread is invoking methods which throw that exception such as sleep). The other approach is
performed by periodically checking the interrupt status flag Thread.interrupted and
performing the handling routine when that flag is set to true.
Write a Java program that illustrates the use of the two approaches described above. Your program
should start by creating two threads, each thread should use different interrupt handling approach.
Then, the program needs to send interrupts to each one of the created threads such that a thread
needs to return (i.e., stop execution) after receiving an interrupt from the main thread. Make sure
to output (print out) the status of each thread before and after being interrupted.
the output should be like this in the image
![Thread: 1 Alive: false State: NEW
Thread: 1 Alive: true State: RUNNABLE
Thread: 1 Has Been Interrupted Using InterruptedException
Thread: 1 Alive: false State: TERMINATED
Thread: 2 Alive: false State: NEW
Thread: 2 Alive: true State: RUNNABLE
Thread: 2 Has Been Interrupted Using Interrupt Status Flag
Thread: 2 Alive: false State: TERMINATED](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff35ea1f3-ccca-4312-a8e8-51d8e06c7dcd%2F78a148bb-87a1-412a-93e7-8f0c63437df6%2Fe7qri8g_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)