• 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

Do different types of Threads exist in JAVA?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends i have some problem related to threads.......

I have once gone through a site there i read that there ar 2 types of threads.

DEMON THREAD.
USER DEFINED THREAD.




It was a online samples of technical Q asked in interviews MNC like Google, Accenture, Cognizent etc

I have gone through various books like

1. A Programmer's Guide To Java Certification, 2nd Edition (Addison & Khalid).

2. Head First JAVA, 2 Edition (Kethy Sierra & Bert Bates).


In these books there is nothing written about the Types of Threads.
Do really the types of threads exist, if yes try to explan there definition.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there are two kinds of thread. Look through the Thread class in the API, and use ctrl-F then daemon.

A non-daemon thread (user thread) keeps running. If there are any non-daemon threads, the JVM keeps running too, until the last non-daemon thread "dies" (or finishes).

A daemon thread does not keep on running if all the non-daemon threads finish. So if you only have daemon threads still running, then the JVM will not keep running, and the daemon threads stop.

More poetically, from C Horstmann, G Cornell, Core Java 2 7/e vol II Advanced Features, Santa Clara: Sun Microsystems Press (Prentice-Hall) (2005) page 19:-

Daemon Threads

You can turn a thread into a daemon thread by calling

t.setDaemon(true);

There is nothing demonic about such a thread. A daemon is simply a thread that has no other role in life than to serve others. Examples are timer threads that send regular "timer ticks" to other threads. When only daemon threads remain, the virtual machine exits. There is no point in keeping the program running if all remaining threads are daemons.

 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
closing as duplicate
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic