}
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