Java program to interrupt the execution of a thread
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program/Source Code:
The source code to interrupt the execution of a thread is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created two classes MyThread and Main. We created MyThread class by implementing the Runnable interface. In the run() method, we handled exceptions using try, catch blocks.
The Main class contains a main() method. The main() method is the entry point for the program. Here, we created a thread. Then we started and interrupted the thread using the start(), interrupt() methods respectively.