• 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

java threads implementation in linux

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iam using Red Hat Linux 7.3 and j2sdk 1.4.2_03 in my system.
I executed the below java program.
My java code:
public class chkprg
{
public static void main(String args[])
{
try
{
Thread.currentThread().sleep(2000);
System.out.println("some string");
}catch(Exception e){}
}
}
while executing this code,i checked the number of java processes using ps command.It showed me eight for about 2 seconds and then to zero after the program quits by printing "some string".
If iam correct,In native thread implementation,each thread is showed as a separate process in the process table.
Then why is it spawning eight processes for just a single main thread?
I tried with some other versions of java(jdk 1.4.0 and 1.4.1_07).I got the same results.
can somebody clear my doubt?
I need a solution immediately please.
thanks in advance
regards
mira.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mira,
Welcome to JavaRanch!
We don't have too many rules round these parts, but we do have our naming policy, which requires that your display name not be a fictitious name. Pleae head over here and update yours, pronto. Thanks, pardner!
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a good question. Run your program, hold down "Control" and press "\" (backslash). You'll get a stack dump like the one shown below.
This stack dump shows you what's going on in every thread running in the JVM. As you can see, there are a whole bunch of them -- not just the one where your code runs, but a thread dedicated to handling UNIX signals, two threads related to garbage collection, and three threads performing internal VM tasks, for a total of seven threads. If you use ps -H to see the ASCII-art "process forest", you'll see that of the eight, one is the parent, and the other seven are the children, as listed in the thread dump.
By the way, a tip: note that sleep() is a static method that can only be used to make the calling thread go to sleep; therefore, you can (and should) simply call it as "Thread.sleep()", without invoking "currentThread()."
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic