Created
October 26, 2017 17:22
-
-
Save javamultiplex/47ce4a8cba8486804d8dd8205c418666 to your computer and use it in GitHub Desktop.
Example of IllegalMonitorStateException present in java.lang package.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javamultiplex.java.lang.exceptions; | |
/** | |
* @author Rohit Agarwal | |
* @version 1.0 | |
* @category java.lang/Exception | |
* @since JDK 1.0 | |
*/ | |
class MyThreadNew implements Runnable { | |
@Override | |
public void run() { | |
display(); | |
} | |
private void display() { | |
try { | |
/* | |
* IllegalMonitorStateException will be thrown because without | |
* owning object's monitor we are calling wait method. | |
*/ | |
wait(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
public class IllegalMonitorStateExceptionDemo { | |
public static void main(String[] args) { | |
MyThreadNew thread = new MyThreadNew(); | |
Thread th = new Thread(thread); | |
th.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment