进程调度优先级JAVA_进程调度算法之最高优先级(Java)

这次是用String的一位数组加上list来实现的,上一次写短进程优先的时候,认为用date类太麻烦了。所以这次直接用String,没想到,还是一样的麻烦,因为我想要表示小时,分钟,秒数,三个时间单位,而不是两个时间单位。所以在从String转换成int,并进行计算的时候,比较麻烦。其中用到了简单的正则表达式,并将时间先转化成秒进行计算。

附上源码:

import java.util.ArrayList;

import java.util.Collections;

import java.util.Comparator;

import java.util.Iterator;

import java.util.List;

public class Priority {

private static String[] PCB = {"0进程名", "1运行状态", "2优先级", "3提交时间", "4需要运行时间", "5完成时间", "6周转时间", "7响应比", "8已执行次数"};

//记录当前时间

static String now = "00:00:00";

//时间片

static int timeSlice = 500;

//用String一维数组先建立几个进程

private static String[] process1 = {"process1", "0", "1", "00:08:20", "00:10:56", "", "", "", ""};

private static String[] process2 = {"process2", "0", "3", "00:01:08", "01:00:02", "", "", "", ""};

private static String[] process3 = {"process3", "0", "2", "00:01:01", "00:10:02", "", "", "", ""};

private static String[] process4 = {"process4", "0", "4", "00:01:01", "00:05:02", "", "", "", ""};

private static String[] process5 = {"process5", "0", "7", "00:01:08", "00:00:02", "", "", "", ""};

private static String[] process6 = {"process6", "0", "9", "00:02:08", "00:30:02", "", "", "", ""};

private static String[] process7 = {"process7", "0", "4", "00:03:08", "00:03:01", "", "", "", ""};

private static String[] process8 = {"process8", "0", "2", "00:05:01", "00:00:02", "", "", "", ""};

private static String[] process9 = {"process9", "0", "1", "00:00:13", "00:11:02", "", "", "", ""};

public static void main(String[] args) {

List list = new ArrayList();

list.add(process1);

list.add(process2);

list.add(process3);

list.add(process4);

list.add(process5);

list.add(process6);

list.add(process7);

list.add(process8);

list.add(process9);

System.out.println(PCB[0] + " " + PCB[1] + " " + PCB[2] + " " + PCB[3] + " " + PCB[4]

+ " " + PCB[5] + " " + PCB[6] + " " + PCB[7] + " " + PCB[8]);

startUp(list);

}

//修复String格式转换为long之后再转换为String而造成的格式不正确

public static String modify(String string) {

int i = string.length();

if (i &#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值