In Java multithreading environment, one thread can send an interrupt to another by calling theinterrupt() method on the Thread object for the target thread (i.e., the thread to beinterrupted). To handle interrupts in a target thread, Java allows two approaches. One is performedby writing an exception handler for InterruptedException (only applicable if the targetthread is invoking methods which throw that exception such as sleep). The other approach isperformed by periodically checking the interrupt status flag Thread.interrupted andperforming 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 programshould 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 threadneeds to return (i.e., stop execution) after receiving an interrupt from the main thread. Make sureto output (print out) the status of each thread before and after being interrupted
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here