• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Threads

 
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if we have 2 threads...one thread will never throw a exception but the other one will throw one...then while both the threads are being executed and the 2nd thread throws an exception what happens to the first threaD? does the program stops?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When an exception is thrown, the callstack for that thread is unrolled til the exception is eventually caught. If the exception is not caught, eventually the exception will be passed to a uncaught exception handler -- of which, there may be a few. Such a handler could be assigned to the thread, or the thread group.... after that, the thread is terminated, as its call stack should now be empty.

Other threads in the JVM should, in theory, be uneffected, and continue to run. The reason I say "in theory", is because it is possible for this exiting thread to affect other threads. For example, if other threads depend on the exited thread. Or the exited thread took a resource, or failed to clean up after itself. etc.

Henry



 
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raju,

As henry mentioned, theoritically, improper termination of one thread does not impact the execution of another thread. You can see this happening in the below code.

The first thread terminates improperly still the second thread gives its proper output.

reply
    Bookmark Topic Watch Topic
  • New Topic