This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Independent Program Using Single JVM

 
Kailash Bajaj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Kailash Bajaj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If what you actually want is a tutorial on threads, try this or search JavaRanch.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic