简体   繁体   中英

Need inputs on troubleshooting Runtime.getRuntime.exec() on Low Memory System ?

I our web application we are using Process myProcess = Runtime.getRuntime.exec(cmd). It is currently deployed using Tomcat hosted on Ubuntu Linux.

This application works fine on my development machine (Core2 duo ,2GB RAM OS:UBUNTU 11.04).

However when i host the same on Virtual Server (1GB RAM,Xeon processor) the Runtime.getRuntime.exec(cmd) call fails. It is unable to create the sub process.

The same sub process is created and we got the expected output on my development machine.

In the application we are calling the java class in the servlet which is deployed in the tomcat is executing well and output is fine. below is code snippet of the same.

from the servlet
uploadservlet.java
+-----------+   
CalculateDuration dur=new CalculateDuration();
Map<String, Integer> durationmap=dur.conversion(al);
+-------------+

Caclulateduration.java
+------------------+
{
     conversion(ArrayList<String> b)
     {

      StringBuilder sb = new StringBuilder();
          sb.append( "hello.o"); /* Name of the sample executable */         
       ...

          Process p = Runtime.getRuntime().exec(sb.toString() ); //struck at this line.subprocess not created on my vps system 

      ...

          +------------------+

The Standalone Caclulateduration.java runs on the Virtual Server.

Could this issue be caused becuase insufficient physical memory (leading to getRunTime failing) on the Virtual Server or i am missing some thing here. Any tools,commands or methods to root cause this problem.

Your inputs are appreciated !

Java's Runtime.exec() before 1.7 uses fork()/exec() to spawn a process. Forking means duplicating the current process, which being a Java application is probably huge. To be able to fork() an application, you need to have enough virtual address space available. How much is enough depends on your OS's memory overcommit settings.

To avoid all this trouble, Java 1.7 (Sun/OpenJDK/...) supports vfork()/exec() and posix_spawn() . posix_spawn() directly spawns a new process, while vfork() shares memory between parent and child until the imminent execve() , so they shouldn't require as much virtual address space to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM