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 = m.track - this.head.index;
sum += distance;
this.head.index = m.track;
m.key = false;
m.run();
//threadList.remove(m);
}
this.head.direction = “left”;
}
}
w