Meaningless Drivel is fun!
The moose likes Java in General and the fly likes Multiple instances of java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Multiple instances of java class" Watch "Multiple instances of java class" New topic

Multiple instances of java class

Neo Snyder

Joined: Feb 14, 2003
Posts: 1
I have written a simple java program
public class test{
public static void main(String args[]){
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

Joined: Dec 10, 2001
Posts: 7023
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 ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
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.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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.

Java API Documentation
The Java Tutorial
Eddy Chang

Joined: Apr 05, 2001
Posts: 27
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 ]
I agree. Here's the link:
subject: Multiple instances of java class
It's not a secret anymore!