• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Exception in synchronized block  RSS feed

 
Greenhorn
Posts: 28
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
 
Master Rancher
Posts: 3276
33
  • 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: 28
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?


 
Marshal
Posts: 60136
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does map[-10][-10] mean?
 
Campbell Ritchie
Marshal
Posts: 60136
188
  • 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: 28
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?
 
author
Sheriff
Posts: 23588
138
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: 28
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!