我有很多任务,例如java -jar task2.jar
和<Parent>
<Child />
<button type="button" />
</Parent>
等等。所有任务都需要不同的时间才能完成。我想同时运行它们并在完成后再次运行。有没有一种解决问题的好方法?
答案 0 :(得分:1)
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...
答案 1 :(得分:0)
是的,您可以在后台模式下运行所有这些说明
long_command with arguments > redirection &
在你的情况下,它将是
java -jar task1.jar &
java -jar task2.jar &
两者都将以后台模式运行,它们将并行运行。
#!/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
您可以将所需条件放在if
区块中。