Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Exception thrown by Thread

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would anyone explain why an uncaught exception thrown by one of the threads in a mulit-thread environment WILL NOT cause the program to terminate immediately?
Where, how and by what is the exception handled?
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kevin,
It might help if you quoted your source or gave an example.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Enthuware Software Support
Posts: 4590
45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. A program has many threads (user and daemon).
2. When a thread encounters an uncaught exception, it dies (not the program). A thread is a part of the whole system. "It" is not the system.
3. If there are still user threads running, the program cannot terminate.
Of course, if the program has only one user thread and if that thread encounters an uncaught exception, the program will terminate.

------------------
Get Certified, Guaranteed!
www.enthuware.com/jqplus

SCJP2 Resources, WebCompiler, Compare Mock Exam Results and More!
www.jdiscuss.com
Your guide to SCJD exam!
www.enthuware.com/jdevplus
 
Kevin Yip
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul. You cleared my wrong belief in that any uncaught exceptions will terminate the program. Perhaps this is due to the fact that most of the time I only ran the main thread and every uncaught exception in it cause it to stop.
As noted by Jane, I've here a program which can issue the situation for those interested:

The output is:
Starting Thread-0
Starting Thread-1
Main Thread ends!
Running Thread-0
Running Thread-1
Thread-0
Thread-1
Thread-0
Thread-1
Thread-0
Thread-1
Thread-0
java.lang.RuntimeException at Test$2.run(Test.java:25)
Thread-0
Thread-0
Thread-0
Thread-0
Thread-0
Thread-0
Process exit...

[This message has been edited by Kevin Yip (edited June 05, 2001).]
[This message has been edited by Kevin Yip (edited June 05, 2001).]
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic