Please suggest how thius can be achieved and best approach to follow.

a) Suppose server1 have application which is started using "java -Xmx512M -jar <app1>.jar" from command prompt from particular directory example C:\proj\application1>
C:\proj\application1>
Based on certain condition I want to stop this <app1>.jar on server1 and

b) Start app.jar on server2 using "java -Xmx2G -jar <app2>.jar" on server 2 from particular directory example C:\proj\application2>

c) Then start "<app1>.jar" on server1 once <app2>.jar finishes some processing.

A shell script? Using ssh?

Make them both sleep while they're not processing, and communicate them using sockets, to switch between one or the other, if you're running in the said's directorys it will use them.
If you want instead to start the app with parameters and stop and start it again then you will have to use most probabily SO's especific commands, so if it is in windows you run the app with cmd for example passing the parameters with the route. -> PD: But to call them up you will then will need some 3rd so's compatible and specific interface to turn them up or down, so if I were you I will go with the first aproach.

Thanks a lot for your response...

Here is some more information...
Please guide which will be appropriate, using sockets, what are SO specific commands ?(I don't have idea about it),
a) It is windows environment server1 is 32-bit and server2 is 64-bit, 64-bit server is used to do some very large processing of files. That is why we are setting memory to each server.
b) At a time there should be only ONE instance of app.jar running either on 32-bit or 64-bit
c) So, if server1 finds some LARGE file it will mark the status as LARGE at db level.
d) As soon as status is LARGE we should stop the application on server1
e) Start application on server2 passing higher memory
f) Once server2 completes the processing, stop the application on it and start application back on server1 with lower memory arguments.

For interface : When main application on server1 (32-bit) is started using "java -Xmx512M -jar <app1>.jar", we laready have swing based small component with 'Start', 'Pause', 'Running' option as in code below
So, if we Pause application on server1 (32-bit), then how can we use the same interface to start the application on 'server2 (64-bit) ' with higher memory?

private void startPause(ActionEvent evt){
	if(button.getText().equals("Start") || button.getText().equals("Paused")){
		button.setText("Running");			
		AppMainFrame._RUN = true;
		this.worker = new SwingWorker<Void, Void>(){
			public Void doInBackground(){
				startApp();		
				return null;
			}
		};
		
		SwingWorker timerWorker = new SwingWorker<Object, Void>(){
			public Object doInBackground() throws TimeoutException, InterruptedException, ExecutionException{
				worker.execute();
				try{
					return worker.get(AppMainFrame._TIMEOUT, TimeUnit.SECONDS);
				}catch( TimeoutException timeoutException){
					status.setText("Thread Timeout");
					logger.warn("AppMainFrame thread timed out - process may have hung on last file.");
					worker.cancel(true);
					logger.fatal("AppMainFrame thread will die after this part fails");
					throw timeoutException;
				}
			}
		};
		timerWorker.execute();
	}else if(button.getText().equals("Running")){
		button.setText("Paused");
		AppMainFrame._RUN = false;
	}
}

public static void main(String[] args){
	javax.swing.SwingUtilities.invokeLater(new Runnable(){
		public void run(){
			new AppMainFrame().setVisible(true);
		}
	});
}

private void startApp(){
	ProcessClient pc;
	while(AppMainFrame._RUN){
		status.setText("Running");
		logger.info("AppMainFrame -> Starting up!");
		pc = new ProcessClient();
		logger.info("AppMainFrame -> Finished!");
		pc = null;
		status.setText("Idle");
		try{
			Thread.sleep(5000);
		}catch(Exception e){
			e.printStackTrace();
		}
	}	
}

Hehe sorry OS (Operating System) commands, like a bat in Windows ajam.
example:
//+++++++++++Begin Bat foo.bat

cd "C:\Documents and Settings\AMONTILLA\Escritorio\RADIO_IM"
java -jar "C:\Documents and Settings\AMONTILLA\Escritorio\apppath.jarr"
pause

//++++++++++++End Bat foo.bat

In Java you put,

getRuntime().exec ("cmd /K  foo.bat")

Where the /K If I remember is to kill the app when you end of executing it, in wich case you the end the jar in the first server. Your interfaces then control this behavours and if that is what you want you can put them to sleep and act like the server side of the program that receive the values, that indicate wich action they should do.
So you can:
1. Identify the data type in your program client-processor.
2. Send the data to the server program of control in the other machine.
3. Close the app client-processor
4. With the interface of control in the other server up the program.
5. Process if is necessary send data to the server in the other machine again,

In this direction you can consult a quick tutorial, very useful about sockets in java with source.

http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html

Thanks a lot for your inputs...
I will give it a try...

Is this thread really about trying to optimise the JVM memory setting so as to minimise the allocation of (unused) virtual memory? Why not just set the vm size to large enough for the worst case and leave it at that? This looks like trying to solve a problem that isn't a problem anyway.

Hi James,

Actually initial application (app.jar) starts on 32-bit so we don't want to set higher memory until required as there are lot of other applications also running.

Whenever there is any large processing (which is rare), we need to execute this same application (app.jar) with higher memory on 64-bit server.

Are we doing anything wrong, any suggestions for the improvement...?

It's not necessarily wrong, but it did seem like a possible case of "premature optimisation"?. Maybe some memory profiling and code review could make the problem, if there is one, go away? Anyway, the normal advice is not to try to optimise Java until you know there is a genuine problem. Certainly on a 64 bit OS I would just allow a huge max VM and stop worrying. 2 Gig on a 32 bit OS is more of a problem :-)

Hehe sorry OS (Operating System) commands, like a bat in Windows ajam.
example:
//+++++++++++Begin Bat foo.bat

cd "C:\Documents and Settings\AMONTILLA\Escritorio\RADIO_IM"
java -jar "C:\Documents and Settings\AMONTILLA\Escritorio\apppath.jarr"
pause

//++++++++++++End Bat foo.bat

In Java you put,

getRuntime().exec ("cmd /K  foo.bat")

Where the /K If I remember is to kill the app when you end of executing it, in wich case you the end the jar in the first server. Your interfaces then control this behavours and if that is what you want you can put them to sleep and act like the server side of the program that receive the values, that indicate wich action they should do.
So you can:
1. Identify the data type in your program client-processor.
2. Send the data to the server program of control in the other machine.
3. Close the app client-processor
4. With the interface of control in the other server up the program.
5. Process if is necessary send data to the server in the other machine again,

In this direction you can consult a quick tutorial, very useful about sockets in java with source.

http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html

Hi,

I started jar using batch file as below

foo.bat (resides in same directory C:\build\project)
-------

cd "C:\build\project"
java -Xmx1000M -jar "C:\build\project\app.jar"
pause

Then in Java code at particular condition I tried this but app.jar is still running...

if(fileSize() > 150000){
  Runtime.getRuntime().exec("cmd /K  foo.bat");
}

If your app don't end with a return statament in the main loop it will not exit, still remove the pause line.

Use /C instead of /K too, for reference http://www.computerhope.com/cmd.htm

If still you can't you can store the pid id before executing and then kill the parent window with something like

"cmd /C taskkill /T /PID 2916" where the /T kill all the childrens

sorry for the double posting...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.