내가 다음 코드에서 틀린거야 어디 보려고 약간의 문제가 발생 해요 :자바 큐 calculaton에게 큐에 만족하지
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 temp = new JobRequest(); // initalised to new JobRequest
Queue q = new LinkedList();
while (true) {
int size = q.size();
for (int i = 0; i < size; i++) {
temp = (JobRequest) q.peek();
if (temp != null) {
availableCPUS += temp.getCores();
}
}
if ((freeCPUS - availableCPUS) >= 0) {
JobRequest nextJob = schedulerPriorityQueue.closestDeadlineJob(freeCPUS - availableCPUS); // returns top job from queue
if (nextJob != null) {
System.out.println("Top priority/edf job:");
printJob(nextJob);
q.add(nextJob);
} else {
System.out.println("Job = null");
}
} else {
break;
}
}
if (temp != null) {
System.out.println("Execution Queue");
for(Object jr : q){
printJob((JobRequest)jr);//print all elements in q
}
}
}
여기에서 일어나고있는 것은 내가를 추가 해요이다 우선 순위 큐에서 최상위 요소를 가져 와서 새 LinkedList에 추가합니다. 하지만 우선 순위 대기열에서 제거 할 작업에는 "코어"라는 값이있는 항목이 있습니다. 나는 핵심 한도 밑에 머물면서 가능한 한 많은 일자리를 없애려고 노력하고있다. 내가 코어 값
를 얻을 곳
temp.getCores()
내가 데 문제는 내 LinkedList의 대기열이 나던 변화에 소요되는 값으로 올바르게 추가 아니라고이다. 내 대기열은 코어 값이 "160"인 5 개의 출력을 표시하지만 500 캡을 설정 했으므로 대기열에서 전혀 만족하지 않습니다.
어디에서 값을 추가 할 지 잘못 생각합니다.
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;
}
}
이 명령문이 실행될 때 -'System.out.println ("Top priority/edf job :");'? –
예 그것은 내 우선 순위 대기열에서 나의 최고 일을 알려준 다음 그 일을 연결된 목록에 추가합니다. 그것이 작동 하는지를 확인하기위한 것입니다. 모두 실행되지만 문제는 내가 코어를 추가하는 방법입니다. 작동하지 않는다 –
'nearestDeadlineJob' 메서드가 무엇을하는지 알 수 있습니까? –