File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Independent Program Using Single JVM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Independent Program Using Single JVM" Watch "Independent Program Using Single JVM" New topic
Author

Independent Program Using Single JVM

Kailash Bajaj
Greenhorn

Joined: Jan 31, 2005
Posts: 3
1.can we have a single JVM execute two threads, each of which is an independent program? That is, can we have a single JVM running two main methods? And can we share data in this case.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
One JVM can run as many threads as you like. There are lots of way that they can share data, such as classes with global (public static) data, using a SQL database, files, sockets, RMI, CORBA.

The following is not beginner material, but for completeness...

The java(.exe) executable is by far the most common way to run a Java application, but not the only one. What it does is it creates a JVM, locates the class specified on the command line, finds the static main() method in that and tells the JVM to run that. This all happens essentially on one thread, but main() may create as many more threads as it likes.

It is possible to write your own native executable program to create a JVM and run Java on it. This would use the Invocation API from the Java Native Interface. You could make that load multiple classes, create additional threads and run the main() or other methods of those classes on those threads.

I strongly suspect that's not what you want, though. You probably just need to write a "wrapper" class with a main() method that fires off the main() methods of various classes, in separate threads.
[ January 31, 2005: Message edited by: Peter Chase ]

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Kailash Bajaj
Greenhorn

Joined: Jan 31, 2005
Posts: 3
Thanks for this. I was bit confused for how can JVM will handle multithreads. I mean may be the out put we require as a graph as well as data at same time.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
If what you actually want is a tutorial on threads, try this or search JavaRanch.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Independent Program Using Single JVM