• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in synchronized block  RSS feed

 
Jerry Ye
Greenhorn
Posts: 25
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I've just written a multi-threaded program and there is an obvious ArrayOutOfIndexException in the synchronized block but the thread just terminated itself without throwing an exception or giving any information. Is that what it's supposed to do?
Thanks
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post some code that compiles, executes and shows the problem?
 
Jerry Ye
Greenhorn
Posts: 25
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Can you post some code that compiles, executes and shows the problem?

 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does map[-10][-10] mean?
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just as well you are getting an exception; that line would behave even worse if you didn't suffer an exception.
 
Jerry Ye
Greenhorn
Posts: 25
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Just as well you are getting an exception; that line would behave even worse if you didn't suffer an exception.

Well, my question is just why I didn't receive any information at console. Has the thread caught it and just terminated itself? If so, how can I know what's going wrong in my thread?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jerry Ye wrote:
Well, my question is just why I didn't receive any information at console. Has the thread caught it and just terminated itself? If so, how can I know what's going wrong in my thread?


First of all, there aren't any synchronized blocks anywhere in the code -- which your subject title led us to believe. Heck, even your original post mentioned it.  In general, subject titles are suppose to help readers with the topic -- a sort of a summary. A title isn't supposed to confuse the readers....

Anyway, to answer your question... When an executor achieves an exception (with a task), it is supposed to save it. When you call the submit() method, you will get an Future instance back. With a Runnable, when you call the get() method of the Future instance, you should get a null value back -- that is, if the runnable terminated normally.

If the Runnable didn't terminate normally, then you will get an ExecutionException thrown from the get() method on that Future instance... and if you call the getCause() method on the exeception, you should get the exception that was thrown by the runnable.


And BTW, why did you expect the exception to be outputted to the console? Did you read a book/documentation that stated this? ... if so, perhaps you shouldn't use that source anymore.

Henry
 
Jerry Ye
Greenhorn
Posts: 25
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
First of all, there aren't any synchronized blocks anywhere in the code
And BTW, why did you expect the exception to be outputted to the console? Did you read a book/documentation that stated this? ... if so, perhaps you shouldn't use that source anymore.


Thanks for your explanation, Henry.
I wrote that title because my original program was inside a synchronized block, but only after I've written a more simple one for demonstration then I found that it can occur without a synchronized block.
I expected the exception to be outputted to the console just because it always did in all other programs that I've written. Perhaps just because it's my first time to study on concurrency. I never realized this problem before so it surprised me.
Thanks again for your help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!