我有一个优先级队列,它按日期顺序列出了来自 sql 数据库的大量作业。然后我得到了最接近的DeadlineJob函数,它得到了最高职位,检查是否有任何其他工作具有相同的日期,然后比较优先级以查看哪个是最高职位。然后我得到了最高职位。
查找原始队列顶部作业:
public JobRequest closestDeadlineJob(int freeCPUS) {
// find top job to determine if other jobs for date need to be considered
JobRequest nextJob = scheduledJobs.peek(); // return top most job
if (nextJob != null) {
System.out.println("Found top EDF job:");
printJob( nextJob );
// what is it's date?
Date highestRankedDate = nextJob.getConvertedDeadlineDate();
// create a temporary queue to work out priorities of jobs with same deadline
JobPriorityQueue schedulerPriorityQueue = new JobPriorityQueue();
// add the top job to priority queue
//schedulerPriorityQueue.addJob(nextJob);
for (JobRequest jr : scheduledJobs) {
// go through scheduled jobs looking for all jobs with same date
if (jr.getConvertedDeadlineDate().equals(highestRankedDate)) {
// same date deadline, soadd to scheduler priority queue
schedulerPriorityQueue.addJob(jr);
System.out.println("Adding following job to priority queue:");
printJob(jr);
}
}
JobRequest highestPriorityJob = schedulerPriorityQueue.poll();
// this is the item at the top of the PRIORTY JOB queue to return
// remove that item from scheduledJobs
scheduledJobs.remove(highestPriorityJob);
return highestPriorityJob;
} else {
return null;
}
}
以下代码将顶级作业处理到队列中:
public void processNextJob() {
/*
* 1. get # of free CPU's still avaialble
* 2. get top most job from priority queue
* 3. run job - put to CPU queue
* 4. develop a CPU queue here
* 5. count cores against freeCPUS and some sort of calculation to sort run times
*/
int freeCPUS = 500;
int availableCPUS = 0;
Queue q = new PriorityQueue();
// while(freeCPUS >= 500)
// {
//
// }
JobRequest nextJob = schedulerPriorityQueue.closestDeadlineJob(freeCPUS); // returns top job from queue
if (nextJob != null) {
System.out.println("Top priority / edf job:");
System.out.print(nextJob.getUserID() + "-->");
System.out.print(nextJob.getStartDate() + "--START-->");
System.out.print(nextJob.getEndDate() + "---END-->");
System.out.print(nextJob.getDeadDate() + "--DROP-->");
System.out.print(nextJob.getDepartment() + "-->");
System.out.print(nextJob.getProjectName() + "-->");
System.out.print(nextJob.getProjectApplication() + "-->");
System.out.print(nextJob.getPriority() + "--PRIORITY-->");
System.out.print(nextJob.getCores() + "-->");
System.out.print(nextJob.getDiskSpace() + "-->");
System.out.println(nextJob.getAnaylsis());
// now got correct job based on earliest deadline / priority
// implement a FIFO queue here / execution stack
// add next job here
} else {
System.out.println("Job = null");
}
}
我需要做的是修复我的糟糕尝试或适应,将我的最接近的DeadlineJob 中的作业放入队列中,然后在我达到 500 个核心限制时停止将它们放入队列中。目前,我只是陷入了 while true 下方的 for 循环中,而且我认为我设定的方式在离开循环后甚至都行不通。
有什么想法吗?
编辑
public void processNextJob() {
/*
* 1. get # of free CPU's still avaialble
* 2. get top most job from priority queue
* 3. run job - put to CPU queue
* 4. develop a CPU queue here
* 5. count cores against freeCPUS and some sort of calculation to sort run times
*/
int freeCPUS = 500;
int availableCPUS = 0;
JobRequest nextJob = schedulerPriorityQueue.closestDeadlineJob(freeCPUS); // returns top job from queue
if (nextJob != null) {
System.out.println("Top priority / edf job:");
printJob( nextJob );
// go through scheduled jobs looking for all jobs with same date
if (nextJob.getCores() <= freeCPUS) {
// same date deadline, soadd to scheduler priority queue
schedulerPriorityQueue.addJob(nextJob);
System.out.println("Adding following job to execution queue:");
printJob( nextJob );
// can use this to get the next top job but need to add calculations to printout the next top job aslong as CPU less than 500
// schedulerPriorityQueue.closestDeadlineJob(freeCPUS);
// schedulerPriorityQueue.addJob(nextJob);
} else if (nextJob.getCores() > freeCPUS) {
System.out.println("Queue temporarily full");
}
// now got correct job based on earliest deadline / priority
// implement a FIFO queue here / execution stack
// add next job here
} else {
System.out.println("Job = null");
}
}
我想我需要在上面实现一个循环并移出 if 语句说接受下一项工作,如果低于 500,再次循环并获得另一个然后将其放入某种新队列中,当满足 500 个核心标准时停止添加新队列