File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes a question on multithreading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "a question on multithreading " Watch "a question on multithreading " New topic

a question on multithreading

Ajit Amitav Das
Ranch Hand

Joined: Dec 14, 2005
Posts: 49
Hi Ranchers .

If i am having 5 threads in a program and 2 are dameon threads and rest 3 are user threads , if either one of them throw a unhandled exception let it be user thread , will all of my threads will stop running or that particular thread will stop running allowing other threads run safely.

Warm Regards<br />Ajit Amitav Das<br />SCJP 1.5
Rohit Suman
Ranch Hand

Joined: Sep 09, 2006
Posts: 37
the answer to your question is that it won't affect the other thread and only the current thread will throw the exception and since the exception is not handeled it will terminate. hope this solves yours doubt
rohit suman
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218

The output (actually, a snapshot of it):

In main, i is 16
In main, i is 17
In main, i is 18
In main, i is 19
In main, i is 0
In main, i is 1
In main, i is 2
In main, i is 3
In main, i is 4
i is 5, i/i is 1
i is 4, i/i is 1
i is 3, i/i is 1
i is 2, i/i is 1
i is 1, i/i is 1
Exception in thread "Thread-0" java.lang.ArithmeticException: / by zero
at Source)
In main, i is 5
In main, i is 6
In main, i is 7
In main, i is 8
In main, i is 9
In main, i is 10
In main, i is 11
In main, i is 12
In main, i is 13

Does that answer your question?
[ September 12, 2006: Message edited by: Aniket Patil ]

SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Ajit Amitav Das
Ranch Hand

Joined: Dec 14, 2005
Posts: 49
Thanks Aniket for a fine example .i got cleared my doubt.
I agree. Here's the link:
subject: a question on multithreading
jQuery in Action, 3rd edition