- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这里遇到了一个问题:当上一个进程执行时间完全结束时执行下一个进程。我需要这个进程基于循环算法执行。 谁能给我提示如何为双处理器编写代码
import java.util.Scanner;
public class RoundRobin {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the number of processes");
int noProcess= keyboard.nextInt();
int[][] process = new int[noProcess][3]; //1st column: process name, 2nd column: arrival time, 3rd column: execution time
System.out.println("Input the Arrival and Execution Time for each process\n"); //in seconds, arrival for each process
for(int i = 0; i < process.length ;i++)
{
process[i][0] = i+1;
System.out.print("Process " +process[i][0]+ " :\t");
System.out.print("Arrival Time : ");
process[i][1] = keyboard.nextInt();
System.out.print("\t\tExec. Time : ");
process[i][2] = keyboard.nextInt();
}
//sorting the processes based on arrival time
for(int index = 0; index< process.length; index++ )
{
int indexOfNextSmallest = RoundRobin.getIndexOfSmallest(index, process);
interchange(index, indexOfNextSmallest, process);
}
System.out.println("ProName\tArrTime\tExecTime"); //table after scheduled.
for(int row = 0; row < noProcess; row++)
{
for(int column = 0; column < 3; column++)
{
System.out.print("" +process[row][column]+ "\t");
}
System.out.println("\n");
}
System.out.print("Enter the Quantum time:"); //in seconds
int qTime = keyboard.nextInt();
// boolean counter = true;//false if all process is completely execute
/**while(counter)
{
}**/
int current =0;
int counter = qTime;
int arrTime = 0;
int index = 0;
while(true)
{
if(process[index][2] >= qTime)
{
process[index][2] = process[index][2]- qTime;
counter = counter + qTime;
System.out.println("Process" +process[index][0]);
}
if(process[index][2] != 0 && process[index][2] < qTime )
{
process[index][2] = process[index][2] - process[index][2];
counter = counter + process[index][2];
System.out.println("Process" +process[index][0]);
}
boolean condition = true;
int i = 0;
while(condition)//check any uncompleted process
{
if(i == process.length){
System.out.println("All Process Executions are completed");
System.exit(0);}
else if(process[i][2] == 0)
{
i++;
}
else
{
if(index < process.length-1)
{
if(counter >= process[index+1][1] )
{ index = index + 1;}
else
{ index = 0;}
}
else
{ index = 0;}
condition = false;
}
}
}
// TODO code application logic here
}
private static int getIndexOfSmallest(int startIndex, int[][] a) {
int min = a[startIndex][1];
int indexOfMin = startIndex;
for(int index = startIndex+1; index <a.length; index++)
{
if(a[index][1] < min)
{
min = a[index][1];
indexOfMin = index;
}
}
return indexOfMin;
}
private static void interchange(int i, int j, int[][] a)
{
int temp0 = a[i][0];
int temp1 = a[i][1];
int temp2 = a[i][2];
a[i][0] = a[j][0];
a[i][1] = a[j][1];
a[i][2] = a[j][2];
a[j][0] = temp0;
a[j][1] = temp1;
a[j][2] = temp2;
}
}
JAva 代码文件:https://skydrive.live.com/redir?resid=45E9B19710622F21!107执行过程中的图像:https://skydrive.live.com/redir?resid=45E9B19710622F21!108
最佳答案
您需要的是一个简单的列表。循环很容易实现为列表。只需从列表的前面删除,然后将其放到后面。
ArrayList<Task> tasksToExecute = new ArrayList<Task>();
// some code here that populates the list the first time
while (needToWork)
{
Task nextTask = tasksToExecute.remove(0); // get the first object
// process the task here
tasksToExecute.add(nextTask); // put the task back on the list
}
这将平均处理列表中的所有任务。
关于java - 循环法 Java : Execution Process Not Occur Based on roundrobin algorithm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13109829/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
我有实体: @Entity @Table(name = "CARDS") public class Card { @ManyToOne @JoinColumn(name = "PERSON_I
我正在尝试计算二维多边形的表面法线。我正在使用 OpenGL wiki 中的 Newell 方法来计算表面法线。 https://www.opengl.org/wiki/Calculating_a_S
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 7 年前。 Improve
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我这里有以下 XML: Visa, Mastercard, , , , 0, Discover, American Express siteonly, Buyer Pay
即将发生的 Google 政策变更迫使我们实现一个对话框,以通知欧盟用户有关 Cookie/设备标识符用于广告和分析的情况。我只想向欧盟用户显示此对话框。我不想使用额外的权限(例如 android.p
本文分享自华为云社区《华为大咖说 | 企业应用AI大模型的“道、法、术” ——道:认知篇》,作者:华为云PaaS服务小智。 本期核心观点 上车:AGI是未来5~10年内,每个人都无法回避的技
我有一个与酒精相关的网站,需要先验证年龄,然后才能让他们进入该网站。我使用 HttpModule 来执行此操作,该模块检查 cookie,如果未设置,我会将它们重定向到验证页面。我验证他们的年龄并存储
在欧盟,我们有一项法律,要求网页请求存储 cookie 的许可。我们大多数人都了解 cookie 并同意它们,但仍然被迫在任何地方明确接受它们。所以我计划编写这个附加组件(ff & chrome),它
以下在 C 和/或 C++ 中是否合法? void fn(); inline void fn() { /*Do something here*/ } 让我担心的是,第一个声明看起来暗示函数将被定义
我是一名优秀的程序员,十分优秀!