Best way to run Perl script from Java EE web application

I am currently working on a WebLogic Java EE project where from time to time an application executes a Perl script to do some batch jobs. In the application, the script is called as

Process p = Runtime.getRuntime().exec(cmdString);


Although this is a dangerous way to run it, it worked correctly until we had a requirement to execute the script synchronously in a for loop. After a couple of runs, we get Not enough space

as the OS is probably exiting from virtual memory when executed in a for loop. As a result, we cannot run the script on the server at all.

I'm desperately looking for a safer and better way to run a Perl script where we don't have to fork the parent process, or at least eat up all the swap space!

The spectrum looks like this:

Appserver - Weblogic 9.52  
JDK - 1.5   
OS - SunOS 5.10 



source to share

3 answers

If you want to keep your code intact and have enough free disk space, you can simply add a large enough swap space to your OS.

Assuming you need 10 GB, this is how you do it with UFS:

mkfile 10g /export/home/10g-swap
swap -a /export/home/10g-swap
echo "/export/home/10g-swap - - swap - no -" >> /etc/vfstab


If you are using ZFS this will be:

zfs create -V 10gb rpool/swap1
swap -a /dev/zvol/dsk/rpool/swap1


Don't worry about this big swap, it won't affect performance as the swap will only be used for virtual memory reservations, not paging.

Otherwise, as suggested in previous answers, one way to avoid the virtual memory problem is to use a helper, that is, a small service that your contact over a network socket (or higher layer protocol like ssh) and that does a remote perl script function.

Note that the issue has nothing to do with the 32-bit or 64-bit JVM, but Solaris does not recompile the memory, and that is by design.



I've had something like this a few times. Since the child process is a fork (very large parent, he can see that all of this is sharing all his memory (using copy on write). I found that the kernel should be able to ensure that it can copy all memory before forking the child , on a 32 bit OS, you quickly run a virtual head.

Possible solutions:

  • Using a 64-bit OS and JVM is pushing the problem down the road until it matters.
  • Send your script to another process (like HTTPD) and collect it with an HTTP request to call it


Create a perl server that reads perl scripts over the network and runs them one by one.



All Articles