This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Will running three instances of javaw.exe really slow down performance? The reason I asked is that I was once tasked to write a Java Instant message system for our team. It runs a receiver and a sender. (The sender is excecuted in a seperate javaw instance which I am thinking about modifying). I have now been tasked with writing another java app that is to be up and running all the time as well. How will something like this affect 800Mhz machines with 128MB of RAM. I don't wanna be bogging down the teams machines.
Ryan Headley<br /><a href="http://www.sudovi.com" target="_blank" rel="nofollow">http://www.sudovi.com</a>
Yes. Each JVM is a seperate process and will use it's own memory space. This means, for example, that a class, like java.lang.Object will be loaded into the memory spaces of each JVM. You can run multiple application in the same JVM. Basicially, you create your own classloader. When you start an app, it checks to see if there's already a JVM running, and if so, makes sure that JVM spawns a new thread and runs the new application. Obviously the first JVM to start up needs a way to announce itself in ways future programs can check when they start up. I know there are solutions out there which do this. I think one of the Java Magazines even gave an exmaple back in 2000. I would also guess that Star Office does something like this.
Joined: Jun 28, 2000
guess I am not quite up to speed on that. Not really sure what you mean. Do I have something in one program that calls the other one? What if the two apps have nothing to do with each other, is this still possible??
Originally posted by ryan headley: guess I am not quite up to speed on that. Not really sure what you mean. Do I have something in one program that calls the other one? What if the two apps have nothing to do with each other, is this still possible??
I believe what Marc was trying to describe is a means to run multiple applications in the same VM by running each application in it't own class loader. I'm not sure how Marc believes you can achieve this but here is one scheme that should work. First, you need two things, an appliction that you could communicate with and possibly, a custom ClassLoader. What you'd pass to this application is the name of an application that you want to execute. The application would then start the application in a new ClassLoader. One of the potential problem with this approach is that (I believe ) System.exit() causes the VM to exit.
Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0672324261/ref=jranch-20" target="_blank" rel="nofollow">Ant Developer's Handbook</a>
Joined: Jan 17, 2001
Originally posted by Kirk Pepperdine: [B] I believe what Marc [B] Oops, that should have been Mark. Sorry Mark 8^\
Joined: Jun 28, 2000
I think I've gotcha. The main app should be something where you would select which app to run...at least that is what I am seeing. In order to get around the System.exit() I suppose you could just .dispose the things you aren't using... Dunno.
Joined: Dec 04, 2000
Yes, that's basically it. I don't think you can override System.exit you(), so need to be sure to never call it from any of your applications. So how do you shut down an application? As follows.... In addition to each application code, there is also some shared Java code. This is a manager class. When a system wants to quit, it lets the manager know. The manager then keeps tract of whether or not it is the last application running, and if it is, the manager calls System.exit(). If it is not the last application, the manager can also tell the classloader to unload the classes (if supported by that version of Java).