Tuesday, March 21, 2023
HomeColdFusionDealing With InterruptedException in Java - FusionReactor

Dealing With InterruptedException in Java – FusionReactor

An InterruptedException is a kind of exemption that happens when a String is waiting, resting, or otherwise inhabited, as well as the string is disturbed by one more String. The disturbance triggers the String to toss an InterruptedException. This exemption signals to the String that it ought to quit what it’s doing as well as departure.

Exactly how you can manage InterruptedException in a Java String:

 public course MyThread expands String {

. public space run() {

attempt {
.// code that might toss InterruptedException 
. Thread.sleep (1000);

.} catch( InterruptedException e) {

.// manage InterruptedException 
. System.out.println(" String was disturbed, leaving");


} public course Key {
. public fixed space primary (String[] args ){

. MyThread myThread = brand-new MyThread();

. myThread.start();

. myThread.interrupt

.}(* )In this instance, MyThread expands the String course as well as bypasses its run technique. In the run technique, we make use of the Thread.sleep( 1000) technique, which can toss an InterruptedException. The exemption is captured in a try-catch block, as well as the message "String was disturbed, leaving" is published to the console.

Generally technique, we begin a circumstances of MyThread. After that we disturb the string by calling myThread.interrupt(). If the string is presently in an obstructed state (e.g., resting), it will certainly toss an InterruptedException, as well as the catch block will certainly manage it.


Most Popular

Recent Comments