• 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: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class thread extends Thread {
public void run(){
System.out.print("hi"+this.getName()+",");
System.out.print(this.isDaemon());
}
public void go(){
System.out.println("in go ..");
this.start();
}
public static void main(String a[]){
thread t1 = new thread();
thread t2 = new thread();
t1.go();
t1.setDaemon(true);
t2.run();
}
}
And the output is :
in go ..
Exception in thread "main" java.lang.IllegalThreadStateException
at java.lang.Thread.setDaemon(Thread.java:1097)
at thread.main(thread.java:17)
hiThread-1,false
Can anybody explain why it throws exception ? Why the main method continues execution even after the exception ?
Thanks in advance.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you not have to do setDaemon() before you start the thread?
And do you really mean t2.run()?
-Barry
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic