Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in thread

 
Frederico Benevides
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why it works, because I thought in "laurel.wait(1000);" the wait has to be inside in a synchronized block or synchronized method, but I don't understand why in here is not in this and it works.

Thank you.





And here, the wait has the problem because is not inside in a synchronized block.


[ March 08, 2006: Message edited by: Frederico Benevides ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the first program, you are calling the wait method from within a try block which has a corresponding catch block that ignores all checked exceptions. If you add a print statement in the catch block to print out the name of the exception, this is one possible output.



In the second program you are not catching and ignoring any checked exception so you get the IllegalMonitorStateException.
[ March 08, 2006: Message edited by: Keith Lynn ]
 
Frederico Benevides
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, is true, how I didn't see that

thank you!
 
Stephen O'Kane
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about this code example (TwoThreads class). It comes from K&B's book, page 756.

Given the above code which letters will eventually appear somewhere in the output? (choose all that apply.)

A. A
B. B
C. C
D. D
E. E
F. F
G. The answer cannot be reliably determined
H. The code does not compile


the answer is:

A, C, D, E, F.

I don't understand why B is not a correct answer, as is it not possible that a InterruptedException (or any other random exception) occurs, therefore B might be printed? Or are these sort of things ignored in the exam. I thought the answer would be G, as it cannot be relibly determined if B will be output or not.

Plus, the book says that on the exam, the number of options for an answer will be given. In this case, does this mean that in the exam they will tell us 5 answers are correct? That would make this question infinitely more obvious.

Thanks for your time
Sok
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic