File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple instances of java class

 
Neo Snyder
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a simple java program test.java
import java.io.*;
public class test{
public static void main(String args[]){
while(true){
System.out.println("hello");
}
}
}
when i run this program using the command
java test& , 10 instances of this program is shown in the process listing.Iam working in linux
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Noe!
On Windows XP Professional, the task manager shows only one JAVA.EXE process (using about 5MB of memory and very little CPU time).
[ April 01, 2003: Message edited by: Dirk Schreckmann ]
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java test&
Not sure what this does in Linux, but if that is a wildcard then perhaps you are invoking multiple programs.
The "correct" syntax is
>java test
which should only start one JVM using one process.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In *nix, the & after a command detatches the newly created process from the terminal. This allows you to continue typing other commands on the command line while the program continues to run in the background.
How do you see that 10 instances of it are running? If you use the "ps" or "top" commands it should only list a signle instance. However, I haven't tried it myself. You have definitely piqued my curiosity. I'll have to check this out when I have a chance at home this evening.
Layne
 
Eddy Chang
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On linux.

$java -version



$java test &
The other java processes listed are child threads spawned by the jvm.

$ps auxwwf | grep echang


What are the other threads? The ones listed in the thread dump.
$kill -QUIT 5257


[ April 07, 2003: Message edited by: Eddy Chang ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic