• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a question on multithreading

 
Ajit Amitav Das
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rohit Suman
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
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
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 Job.run(ThreadDemo1.java:7)
at java.lang.Thread.run(Unknown 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 ]
 
Ajit Amitav Das
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Aniket for a fine example .i got cleared my doubt.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic