• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Doubts in threads !

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
look at this code:
class A{
public static void main(String s[]){
System.out.println("Hello");
}
}
My question is how many threads run concurrently(including JVM and gc)while executing the above code?
Plz give an elaborate reply..
Thanking in advance..,
Manoj
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in this program the only non-daemon thread is the main thread.
there may be n numbers of daemon threads, of which gc is one example. the jvm exists only when all the non-daemon threads are dead. as for daemon threads, they are system threads and don't belong to a process as such.
 
Manoj Chandran
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anshuman,
Can u plz differentiate between daemon n non daemon threads?
Manoj
 
Anshuman Acharya
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am giving a reference Baldwin's Java Tutorial
Daemon Threads
According to Java Primer Plus, if you set a thread as a daemon thread using setDaemon() method, you are
specifying that the thread belongs to the system and not to the process that spawned it.Daemon threads
are useful if you want a thread to run in the background for extended periods of time.
According to Deitel and Deitel, Java, How to Program, "A daemon thread is a thread that runs for the
benefit of other threads."
Daemon threads run in the background and do not prevent a program from terminating. For example, the
garbage collector is a daemon thread.
A program can include a mixture of daemon and non-daemon threads. The Java virtual machine will exit
when only daemon threads remain in a program.

satisfied?
 
Arthur, where are your pants? Check under this tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic