• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Independent Program Using Single JVM

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If what you actually want is a tutorial on threads, try this or search JavaRanch.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic