About Question enthuware.ocpjp.v7.2.1557 :
Moderator: admin
-
- Posts: 14
- Joined: Thu Apr 18, 2013 2:05 pm
- Contact:
About Question enthuware.ocpjp.v7.2.1557 :
I don't understand how catch block will be execute here ? i can't see any reason that will throw InterruptedException.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1557 :
Right. It is not throwing InterruptedException. The assignment is after the catch block.
-Paul.
-Paul.
-
- Posts: 14
- Joined: Thu Apr 18, 2013 2:05 pm
- Contact:
-
- Posts: 62
- Joined: Fri Aug 07, 2015 2:16 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1557 :
what would be the answer if the assignment where in the catch block?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1557 :
If the assignment were in the catch block, you would have to interrupt the hello thread while it is sleeping. You can do that by calling t.interrupt(); in main.
However, main may still fail to print 20 because the main thread could keep running and print 0 before the code for assignment gets to run.
So you could add t.sleep(2000); after t.interrupt() to see that assignment is done and then the value is printed.
You should try out various options to see how it works.
HTH,
Paul.
However, main may still fail to print 20 because the main thread could keep running and print 0 before the code for assignment gets to run.
So you could add t.sleep(2000); after t.interrupt() to see that assignment is done and then the value is printed.
You should try out various options to see how it works.
HTH,
Paul.
Who is online
Users browsing this forum: No registered users and 9 guests