我想创建一个运行队列中所有作业的方法(作业列表)。我创建了一个方法来运行一个作业(runAJob
),下面的方法是运行队列列表中的所有作业,直到时间(myTimeLeft)用完。现在,当我运行方法
时,这段代码总是留下 1 个 ArraLyist 。runAll
有人能告诉我为什么错了吗?
/**
* Run the first job on the queue if there is enough time on the clock and the job queue list is not empty.
* And move the job to the finished jobs list.
*/
public void runAJob(){
myJobDuration = myJobInQueue.get(0).getDuration();
if(!myJobInQueue.isEmpty())
{
if (myJobDuration < myTimeLeft)
{
myTimeLeft = myTimeLeft - myJobDuration;
myFinishedJobs.add(myJobInQueue.get(0));
System.out.println("A job is running: " + myJobInQueue.get(0).getName());
myJobInQueue.remove(0);
}
else
{
System.out.println("Not enogth running time left, please add time on the clock.");
}
}
else
{
System.out.println("No pending job on the list.");
}
}
/**
* Run all the jobs on the queue in order until it runs out of time.
*/
public void runAll()
{
int counAJob =0;
while (myJobDuration < myTimeLeft && !myJobInQueue.isEmpty()) {
// get next item from queue
runAJob();
System.out.println("A job is running: ");
}
}