0

We are using Java 8 and have more that 10 shell scripts. We are calling 10 shell scripts in Java in Spring Boot application using below approach:

  1. Runtime runtime = Runtime.getRuntime(); Process process = Runtime.exec(command); process.waitFor();

  2. ProcessBuilder p = new ProcessBuilder(command); p.start();

It is working fine as expected. But it is consuming server memory and finally it is creating out of memory issue. Even I closed all resource in finally block.

Still I am facing memory issue. Is it the right approach to call shell script in Java?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Check ProcessBuilder https://stackoverflow.com/a/526287/8258942 – Nitin Bisht Jun 01 '20 at 18:24
  • You should post more code. Are you intercepting the sysout/syserr of the process? How do you interact with it? – pafau k. Jun 01 '20 at 18:28
  • Are you sure it's an out of memory problem? Could it be a blocking issue? – Dan M Jun 01 '20 at 18:49
  • I have tried with prcoss builder and I have added in my code Runtime.getRuntime().freememory()...Once my process completed and it is reducing free memory – rasmiranjan Jun 01 '20 at 19:21
  • Check ProcessBuilder stackoverflow.com/a/526287/8258942 –I have tired usig process builder but it is reducing memory every process comeplted.I have addd logger and i saw that – rasmiranjan Jun 01 '20 at 19:25
  • What the process does? How much memory it consumed (initial, regular, max)? Open jvisualVm and inspect memory to see what it stores, then might be you can mitigate. – HoaPhan Jun 01 '20 at 19:42

0 Answers0