By necessity, the operating system loads each VM into its own separate process slot. Consequently, each VM is forced to duplicate the other's initialization efforts and resource allocations. Specifically, each VM is required to load the JDK core classes into their respective heap spaces. Running several Java applications in the same VM would eliminate this duplication of effort. There's an analogy in the world of operating systems.
System engineers have long recognized that portions of statically linked executables contain read-only text that's potentially shareable. They knew that certain performance benefits could be realized if processes could share this text. This knowledge motivated them to develop shared-text libraries. These libraries are loaded only once and are dynamically linked to executables. Nowadays, most operating systems support the concept of a shared text library (or DLL - dynamic-link library). For example, dynamically linked UNIX processes make references to the shared library libc.so. The OS ensures that these processes share the text portion of that library.
By introducing shared libraries, system engineers reduced the overall requirements for system memory. One side effect: the scheme also places less stress on the IO channels and other system resources. This example hints at performance benefits that might be available if you could run several Java applications in the same VM.
Returning to the original thread of discussion and the question, "How do you launch multiple applications?", I suggested a way you might easily build this capability. Even though I was confident that my post was correct, I had never actually built an application launcher. A few seconds after I hit the send button I decided to stick around and read my own advice. I read my posting and thought, "Is it really that easy? Maybe I'd better check out my own advice." What follows are the lessons I learned as I "ate my own dog food."
What I'm Looking For
I'd like to have the flexibility to run several Java 2 applications concurrently in the same JVM. These applications need to function in a secure environment that isolates them from each other to the greatest extent possible. The use of this multiple application launcher (MAL) should be transparent to the application. Finally, all applications should be able to share common read-only resources. Let's start by investigating the current launch technology to see what we can learn and possibly reuse.
Launching a Java Application
MAL needs to mimic the behavior of the standard application launcher. I began my voyage of discovery by reviewing the way a Java application is loaded and then executed. I quickly discovered that starting up a VM initiates a complex sequence of events. Once the initialization sequence has completed, I'm left with a VM that's ready to load a Java class and invoke a standard entry point method. (The complete source code for this article can be downloaded from www.sys-con.com/java/sourcec.cfm.)






