Reputation: 321
I have many tasks, which are something like java -jar task1.jar
and java -jar task2.jar
and so on. All the tasks take different time to complete. I want to run them simultaneously and run again when completed. Is there a good way to solve the problem?
Upvotes: 0
Views: 101
Reputation: 5940
You want to run both commands in background and restart them as soon as they will finish with a 10 minutes pause (your comments here below).
Something like this will restart each command independently:
$ while true ; do java -jar task1.jar ; sleep 600 ; done &
$ while true ; do java -jar task2.jar ; sleep 600 ; done &
If you want to wait both commands to finish before restarting them:
$ while true ; do
java -jar task1.jar &
java -jar task2.jar &
wait
sleep 600
done
As per you comment I did add a 10 minutes pause before re-running the commands...
Upvotes: 1
Reputation: 2962
yes, you can run all those instructions in background mode
long_command with arguments > redirection &
Here in your case, it would be
java -jar task1.jar &
java -jar task2.jar &
Both will run in background mode and they will run in parallel.
#!/bin/sh
a=0
n=10
while [ $a -lt $n ]
do
java -jar task1.jar &
java -jar task2.jar &
a=`expr $a + 1`
done
#!/bin/sh
a=0
while true
do
echo "Running "$a "th time"
if [ $a -eq 5 ]
then
break
else
java -jar task1.jar &
java -jar task2.jar &
fi
a=`expr $a + 1`
done
You can put your desired condition in if
block.
Upvotes: 0