我有一个优先级队列,按日期顺序列出来自sql数据库的作业的aload。然后,我得到最接近的DelinelineJob函数,获取最高职位,检查是否有其他工作具有相同的日期,然后比较优先级,以查看哪些是最重要的工作。然后我回到最高职位。java优先级队列队列适应
查找原始队列最高职位:
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");
}
}
我需要做的是解决我的可怜的企图或改编,在将工作从什么我最近的DeDeline工作进入队列,然后当我达到我的500核心限制时停止将它们放入队列中。目前我只是被困在while循环下面的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核心标准时,停止添加到新队列
没有真正回答这个问题,但有一个原因,你不能做在SQL中的数据的多个过滤? – SimonC 2013-02-21 14:13:23
另外,当所有500(!)核心都忙时应该是什么样的行为?新工作应该被拒绝还是排队? – SimonC 2013-02-21 14:20:28
由于约束条件以及事物设置为否,我只需将“x”个工作量添加到队列中(不知道哪种类型是最好的),即核心限制低于500并且无法再添加从队列中或已满,然后停止添加,直到空间变为空闲。他们将留在原来的队列,直到空间变得可用,把他们放在“执行队列”,我试图在这里设置 – 2013-02-21 14:21:40