Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package miscellaneous;
- public class ThreadDemo {
- public static void main (String args[]) {
- final Thread t = new Thread(new Runnable() {
- public void run () {
- new DoSomething().doSomething();
- }
- });
- t.start();
- Thread t2 = new Thread(new Runnable () {
- public void run () {
- try {
- Thread.sleep(2000);
- t.interrupt();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- });
- t2.start();
- }
- static class DoSomething {
- public synchronized void doSomething () {
- try {
- wait();
- } catch (InterruptedException e) {
- System.out.println("Interrupted :(");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment