| Author |
java threads implementation in linux
|
mira
Greenhorn
Joined: Mar 15, 2004
Posts: 2
|
|
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.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
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!
|
[Jess in Action][AskingGoodQuestions]
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
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()."
|
 |
 |
|
|
subject: java threads implementation in linux
|
|
|