Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with sample multi-threaded network test

 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi, I am using the above code to test my network functionality. When I run the program I notice though if the method makeReservation throws an exception, like, for example, the user has booked the room already, the test does not complete. Is this generally the case with threading, ie. that if 1 thread throws an exception, the whole testing application does not complete correctly and is just suspended? I've very new to threading, but I thought if multiple threads were running and 1 became suspended, the other threads could continue running, or is this an incorrect assumption? In my case, for example, one of the threads, throws an exception in the makeReservation method "User Booked already", but the test is suspended after this. I ran the same type of test for the data layer and got the same error. As I am new to multi-threading, any ideas are welcome. Damn, multi-threading, so fast, but slowing me down.
 
Nicolas Kal
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,

If the following method is synchronized controller.makeReservation(28,data); then when the exception is thrown the thread is suspended inside that synchronized method and the lock is not relaesed, as a result all waiting threads are blocked.

Regards,
Nicolas
 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your reply Nioclas, actually solved the issue, when the user checked if room booked already, I set a flag to try and avoid unlocking, which I shouldn't have. Using the flag for some business implementation exceptions to avoid calling the unlock mechanism in the finally block. Thanks for your time and effort, much appreciated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic