• 大小: 19KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-02-09
  • 语言: Java
  • 标签: 操作系统  java  

资源简介

使用Java实现操作系统中移动臂磁盘调度算法,包括先来先服务调度算法、最短寻找时间优先调度算法、电梯调度算法、单向扫描和双向扫描调度算法,有简单的图形用户界面

资源截图

代码片段和文件信息

import javax.swing.*;

//对访问序列进行处理 将结果显示在logPane上
public class Arithmetic extends JPanel{
/**
 * 
 */
private static final long serialVersionUID = 1L;

LogPane log;
Thread thread;
int sleeptime=200;
public Arithmetic(){  
log=LogPane.getLog();
}   

//冒泡排序算法
//使用冒泡法从小到大顺序排列
int []bubble(int cidao[]int m){
int ij;
int temp;
for(i=0;i for(j=i+1;j     if(cidao[i]>cidao[j]){
temp=cidao[i];    
cidao[i]=cidao[j];
cidao[j]=temp;   
}
}
return cidao;
}

//先来先服务算法 FCFS
public void FCFS(int cidao[]int now)
{  
int sum=0;//总寻道长度  
int ij;
int count=0;  
int len=0;  
float ave = 0;//平均寻道长度           
sum+=Math.abs(cidao[0]-now);
count=count+1;
String buffer=now+“ “;
len=cidao.length;
//输出磁盘扫描序列
for(i=0;i            if(cidao[i]>0){
                buffer+=cidao[i]+“ “;
     log.addLog(“第 “+(i+1)+“ 次服务的柱面号“+cidao[i]);
            }           
}                   
for(i=0j=1;j sum+=Math.abs(cidao[j]-cidao[i]);              
count++;   
}
ave= sum/len;
log.addLog(“磁盘扫描序列为: “+buffer.toString());     
log.addLog(“总寻道长度:“+sum);
log.addLog(“平均寻道长度:“+ave); 
}

//最短寻道时间优先调度算法 SSTF
public void SSTF(int cidao[] int now) {
int k = 1; // 当前柱面在序列中的位置
int L R len = 0;// L是比当前柱面小且最近的位置 R是比当前柱面大且最近的位置
int i j sum = 0;
float ave;

len=cidao.length;
cidao = bubble(cidao len); // 调用冒泡排序算法排序
String s = ““;
for (int z = 0; z < len; z++)
s += cidao[z] + “ “;
log.addLog(“磁道序列从小到大排序为:“ + s);

//分三种情况对排序后的序列分析
// 若当前柱面号大于请求序列中最大者则直接由大向小依次给予各请求服务
if (cidao[len - 1] <= now) {
String buffer = now+“ “;
for (i = len - 1j=0; i >= 0; i--j++)
{
buffer += cidao[i] + “ “;
log.addLog(“第 “+(j+1)+“ 次服务的柱面号“+cidao[i]);
}
log.addLog(“磁盘扫描序列为: “ + buffer.toString());
sum = now - cidao[0];
}

// 若当前柱面号小于请求序列中最小者则直接由小向大依次给予各请求服务
if (cidao[0] >= now) {
String buffer = now+“ “;
for (i = 0; i < len; i++)
{
buffer += cidao[i] + “ “;
log.addLog(“第 “+(i+1)+“ 次服务的柱面号“+cidao[i]);
}
log.addLog(“磁盘扫描序列为: “ + buffer.toString());
sum = cidao[len - 1] - now;
}

// 若当前柱面号大于当前请求序列中最小者并且小于最大者
if (now > cidao[0] && now < cidao[len - 1]) {
StringBuffer buffer = new StringBuffer(now+“ “);
// 确定当前柱面在已排的序列中的位置
while (cidao[k] < now) {
k++;
}
L = k - 1;
R = k;

// 当前柱面在请求序列范围内
i=0;
while ((L >= 0) && (R < len)) {
// 选择与当前柱面最近的请求给予服务
if (now - cidao[L] <= (cidao[R] - now)) {
buffer.append(cidao[L] + “ “);
sum += now - cidao[L];
now = cidao[L];
log.addLog(“第 “+(i+1)+“ 次服务的柱面号“+now);
L--;
} else {
buffer.append(cidao[R] + “ “);
sum += cidao[R] - now;
now = cidao[R];
log.addLog(“第 “+(i+1)+“ 次服务的柱面号“+now);
R++;
}
i++;
}

// 磁头移动到序列的最小

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-01-03 10:36  Mobile Arm\
     文件         301  2018-12-29 08:46  Mobile Arm\.classpath
     文件         386  2018-12-29 08:46  Mobile Arm\.project
     目录           0  2019-01-03 10:36  Mobile Arm\.settings\
     文件         598  2018-12-29 08:46  Mobile Arm\.settings\org.eclipse.jdt.core.prefs
     目录           0  2019-01-03 10:36  Mobile Arm\bin\
     文件        9545  2019-01-03 09:59  Mobile Arm\bin\Arithmetic.class
     文件        5686  2019-01-03 09:55  Mobile Arm\bin\ArithPane.class
     文件        5586  2019-01-03 09:59  Mobile Arm\bin\DiskOperation.class
     文件        1666  2019-01-03 09:59  Mobile Arm\bin\LogPane.class
     目录           0  2019-01-03 10:36  Mobile Arm\src\
     文件       11320  2019-01-03 09:59  Mobile Arm\src\Arithmetic.java
     文件        8328  2019-01-03 08:30  Mobile Arm\src\ArithPane.java
     文件        3965  2019-01-03 09:59  Mobile Arm\src\DiskOperation.java
     文件         936  2019-01-03 09:59  Mobile Arm\src\LogPane.java

评论

共有 条评论