473,414 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to excute multiple program into a single JVM process.. Pravin Mangalam

I was searching details about the JVM. How JVm call main() method, how i can execute multple Java file into a single JVM process.
Mar 14 '14 #1
5 3130
chaarmann
785 Expert 512MB
How JVm call main() method,
The java compiler has already compiled the java program (including the main method) into bytecode. Now the JVM loads this bytecode, searches for the main() method and executes it to start the program.

how i can execute multple Java file into a single JVM process.
Just load the java file (classloader) and execute one of its method in the main thread or in a new created thread (Thread.run()). Or write a static initializer block inside your java file that will execute a method of your java file. Static initializers are executed immediately after a class is loaded.
Mar 17 '14 #2
Sir can you please give an example...
Mar 18 '14 #3
chaarmann
785 Expert 512MB
For what do you need an example (that you cannot find by google) ?
For controlling the class loader? For writing your own java compiler regarding compilation of the main method?
For writing a multi-threaded program? How to write a static initializer block?
Please be more specific. The problem with the general stuff is that I could write 20 pages or more for help, but it may not contain the help you need for your special case.
The best way is: you list the code here that you already have written yourself and tell us where you are stuck, and we can help you out in this specific case.
Mar 18 '14 #4
let me explain My problem...

cmd>java Test

My above statement excute one JVM and there will be one main thread. ok

Now

cmd>java Test2

this statement also execute another JVM which occupy another memory space and main thread.

Now my Questoin : i want to execute Test2 java program into the First Running JVM. this save my memory and time also which taken for activating a new JVM.

it means in a single JVM how can ii create multiple main thread..
Mar 20 '14 #5
chaarmann
785 Expert 512MB
Thanks for your explanation. That makes it much clearer and I am glad to give you a helpful answer now. What you need is the knowledge about threads. You can read about it in detail for example if you google for "java simple thread example".
In your case, you should rename the methods "main" in both your files Test.java and Test2.java to "run()" and add "extends Thread" to both classes.
Now you will write a new file, let us call it "ThreadStarter", which you will run from the command line (shell) with "java ThreadStarter".

Expand|Select|Wrap|Line Numbers
  1. class ThreadStarter {
  2.     public static void main (String[] args) {
  3.         new Test().start();
  4.         new Test1().start();
  5.     }
  6. }
By the way, if you want to keep the threads running after ThreadStarter and the shell finishes, read about "Demon" threads.
Mar 20 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Maciej Sobczak | last post by:
Hi, I'm interested in embedding the Python interpreter in a C++ application. What I miss is the possibility to create many different interpreters, so that the stuff that is running in one...
4
by: skn | last post by:
Hello, I have written a very simple java class file, which invokes a Python script using JEP. Code snippet:- ------------------- Jep jep = new Jep(false);...
3
by: serge calderara | last post by:
Dear all, I have a vb.net application which start with a sub main procedure. inside this sub main procedure I create a and instance from an assembly x like as follow: sub main() ..... ...
0
by: herbert | last post by:
What is the purpose/advantage/disadvantage of running multiple Windows Services in the same process? (defining ServicesToStart = ... in the first service class) I found one hint saying "this...
5
by: Shuaib | last post by:
I wonder if anybody could shed some light on a problem I am encountering. I have written a program in C that runs on Solaris 2.8. At busy times of the day there may be multiple instances of it...
7
by: jsale | last post by:
I have made an ASP.NET web application that connects to SQL Server, reading and writing data using classes. I was recommended to use session objects to store the data per user, because each user...
2
by: SharpCoderMP | last post by:
i'm trying to embed multiple program icons in my executable. the only way so far i managed to do that is to embed native win32 resource file with multiple icons. it works, but... when i create a...
8
by: mandydhaliwal | last post by:
Hi all, I am porting a win32 c++ program on Linux which first reads a list of processes and their paths from a file.Then this program should launch all of thesese processes. I tried to...
19
by: Zytan | last post by:
I want multiple instances of the same .exe to run and share the same data. I know they all can access the same file at the same time, no problem, but I'd like to have this data in RAM, which they...
0
by: lovetopravin | last post by:
Please any one can tell me Link of the sites where i can take the exams of C/c++/Java. I'm also want to take certification of these Languages. Pravin Mangalam
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.