Answer the question
In order to leave comments, you need to log in
Calling console scripts from java
Greetings!
Interested in the true-way of calling console scripts from Java.
Let's say there is a script that needs to be pulled often. Let's say once a minute multiplied by the number of clients taken from the database, followed by processing of not very large responses received with a delay.
The Runtime.exec() method will create a system process for each call, which seems somewhat intimidating to me if there are about 1000 clients.
How to organize this more competently?
Answer the question
In order to leave comments, you need to log in
How are you going to run a shell script without starting a new process?
You can write scripts in groove, then you can run them without creating a new process
In unix, starting a new shell script (if it is a shell script) takes a fraction of a second (for more details, say the time command), which is relatively small compared to the frequency of launch. There is nothing wrong with creating a new process.
But if this is a java program, then its initialization time can be significant. It is better not to restart such programs often.
But if you want to touch the basics of Jedi art: make a daemon that will start up, do a fraction of the work and fall asleep for a minute, and your Java code will kick it with a message to the socket once a minute, as well as revive and restart when it freezes / crashes .
In addition to the above. Those. that's right, it's obviously not possible to run a script without running a shell)
Hmm, so spawn one process and twitch it all the time, giving it a script. Or take the script out into the native environment in some way (by a daemon, as mentioned above, or by a scheduler, or something like that).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question