Java~操作系统实验 模拟电梯调度算法,实现对磁盘的调度。(1)

}

public class DiskScheduling extends Thread {

//需要一个链表去存储去存储要访问磁盘的线程

//一个count记录访问次数

//sum去记录访问距离

//还需要一个磁头

//还需要一个最大磁道是多少

private List threadList = new LinkedList<>();

private int count;

private int sum;

private Head head;

public static final int MaximumTrack = 200;

//在构造函数里初始化磁头

public DiskScheduling(int index, String direction) {

this.head = new Head(index, direction);

}

//需要一个方法往链表为添加程序

public void add(int[] tracks) throws InterruptedException {

//创建线程 线程的名字就是他有寻找的磁道地址

for (int track : tracks

) {

MyRunnable myRunnable = new MyRunnable(track);

threadList.add(myRunnable);

}

//将链表按要寻道的地址进行排序

threadList.sort(new Comparator() {

@Override

public int compare(MyRunnable o1, MyRunnable o2) {

return o1.track - o2.track;

}

});

this.start();

this.join();

//worke();

}

@Override

public void run() {

while (this.count != threadList.size()) {

while (this.head.direction.equals(“right”)) {

for (MyRunnable m : threadList

) {

if (m.track >= head.index && m.key) {

count++;

int distance 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值