-1

I cannot understand why we need to synchronized the wait() method. I can get java.lang.IllegalMonitorStateException after I removed this synchronized block. http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ315_021.htm

Cacheing
  • 3,431
  • 20
  • 46
  • 65
  • Read this to find out more about synchronization http://javarevisited.blogspot.com.au/2011/04/synchronization-in-java-synchronized.html?m=1 you must be clear when you ask questions... Search google a little deeper before posting here man otherwise people will -1 you as you can see lol – Savlon Feb 01 '13 at 05:15
  • @Savlon: I know about synchronization. But I cannot understand why there are multiple threads accessing this method. – Cacheing Feb 01 '13 at 05:28
  • @Savlon: Can you point out which threads access this method? – Cacheing Feb 01 '13 at 05:30
  • 2
    http://stackoverflow.com/questions/2779484/why-wait-should-always-be-in-synchronized-block This question covers it pretty well in general. – AnthonyM Feb 01 '13 at 05:43

1 Answers1

0

Actually, the problem is: wait() has to be in synchronized block. We can refer to: Why must wait() always be in synchronized block, answered by AnthonyM

Community
  • 1
  • 1
Cacheing
  • 3,431
  • 20
  • 46
  • 65