In the below question from K&B mock tests:Practice Exam 2 ,I think " Andi " has to be printed as it runs in separate thread,Also after which we are trying to start t2 for second, the point where we get IllegalMonitorSateException.As per my thinking the answer should only be F,( which contains both "Andi" and Exception) but confused how E is also correct , can you please help Thanks.
Matthew Brown wrote:Remember the three threads (including the main one) can execute in any order, switching control at any time. What happens if you attempt to restart t1 before it's had a chance to print anything?
here we are restarting t2 and not t1, that to after staring t1,
so t1 should have no problem in printing "Andi"( at any time), and option E is not having "Andi" in output that is what my question is!
Doesn't matter. You have no idea what order things that are in different threads are going to happen in. So you've no idea at what stage the exception will be thrown. If the exception happens before t1 prints something out, you can get E.