1

I'm using Java EE and Spring and I have a method with a ProcessBuilder inside:

private void conversion(String path, String name, String timeSample, String timeout) throws Exception {        
        ProcessBuilder pb = new ProcessBuilder("java", "-jar", "Conversion.jar", path, name, timeSample, timeout);

so each time I call this method it creates a new process.

These processes take a lot of resources so I would like to have up to 5 processes running simultaneously

I call the method inside an async method so the user isn't aware about the waiting.

Is there a simple solution or I have to implement a queue where insert all the request and manage them? Thanks

luca
  • 3,248
  • 10
  • 66
  • 145
  • 1
    maybe that post can help you http://stackoverflow.com/questions/54686/how-to-get-a-list-of-current-open-windows-process-with-java – Mr_Thorynque Oct 05 '16 at 08:28
  • Is your goal to strictly ensure that the `conversion` method is called an exact number of times or to limit the number of processes that are executing at the same time to a predefined limit? – Sean Mickey Oct 05 '16 at 08:30
  • the second, these processes take a lot of resources so I would like to have up to 5 processes running simultaneously – luca Oct 05 '16 at 08:38
  • You could try to use ManagedExecutorService https://docs.oracle.com/javaee/7/api/javax/enterprise/concurrent/ManagedExecutorService.html and set a maximum thread size. You have to block the threads with the process. – simdevmon Oct 05 '16 at 10:03
  • This method can be called through web interface, therefore the same thread can create more processes (if the user calls it one more time before that the previous process is ended ) – luca Oct 05 '16 at 10:20

0 Answers0