資源簡介
用java編寫的一個調度算法,是計算機操作系統里的一個算法的演示程序
附源代碼和設計報告

代碼片段和文件信息
package?math;
//主函數及算法
import?java.text.SimpleDateFormat;
import?java.util.Date;
import?java.util.Random;
import?java.util.Vector;
import?view.View;
/**
?*?多級反饋隊列算法
?*?@author?諶毅
?*
?*/
public?class?Arithmetic?{
private?static?SeqQueue[]?sq=new?SeqQueue[4];
private?static?View?view=null;
private?int?num=1time=-1doflag=0threadNum=0;
private?static?int?maxthreadnum=5;
//time為暫停計時用||doflag標示出當前正在執行的隊列
private?boolean?addThreadFlag=false;//addThreadFlag判斷添加進程是否還在執行false為在運行true為停止
private?boolean?delThreadFlag=false;//delThreadFlag判斷添加進程是否還在執行false為在運行true為停止
private?boolean?newflag=true;//newflag標示在執行過程中是否有比自己優先級高的進程加入隊列true為沒有false為有
private?boolean?isStop=false;//表示是否結束執行進程
private?Work?work=null;//保存每次從隊列取出的進程
private?SimpleDateFormat?sdf=new?SimpleDateFormat(“hh:mm:ss“);//定義時間顯示格式
private?Thread?addthread=nulldelthread=null;//定義兩個線程
public?Arithmetic()?{
for(int?i=0;i<4;i++){
sq[i]=new?SeqQueue(5(int)Math.scalb(1?i+1));//構建隊列
}
view=new?View(sq);//實例化面板
// maxthreadnum=view.getThreadNum();
// while(maxthreadnum>10||maxthreadnum==0){
// maxthreadnum=view.getThreadNum();
// }
addthread=new?addThread();
delthread=new?delThread();
addthread.start();
delthread.start();
}
/**
?*?用于啟動添加進程
?*?@author?諶毅
?*/
public?void?startAddThread(){
addthread=new?addThread();
threadNum=0;
addThreadFlag=false;
addthread.start();//啟動添加進程
}
/**
?*?用于啟動執行進程
?*?@author?諶毅
?*/
public?void?startDelThread(){
delthread=new?delThread();
isStop=false;
delThreadFlag=false;
delthread.start();//啟動執行進程
}
/**
?*?用于停止添加進程
?*?@author?諶毅
?*/
@SuppressWarnings(“deprecation“)
public?void?stopAddThread(){
addThreadFlag=true;
addthread.stop();
addthread=null;
}
/**
?*?用于停止執行進程
?*?@author?諶毅
?*/
public?void?stopDelThread(){
isStop=true;
}
/**
?*?自動添加進程的方法
?*?@author?諶毅
?*
?*/
class?addThread?extends?Thread{//添加進程
@SuppressWarnings(“deprecation“)
public?void?run()?{
while(true){
try{
threadNum++;
Thread.sleep(new?Random().nextInt(5000));
int?time=0;
while(time==0){
time=new?Random().nextInt(20);//隨機生成進程要完成的時間
}
num++;
Work?work=new?Work(“進程“+(num-1)time);//生成一個進程
int?flag=addInSeqQueue(0?work);//把進程放入隊列
if(flag newflag=false;//表示有優先級更高的進程進入隊列
}
View.setSq(sq);//更新面板數據
view.showWork();
view.addMes(“‘進程“+(num-1)+“‘于“+new?SimpleDateFormat(“hh:mm:ss“).format(work.getInDate())+“進入“+(flag+1)+“號隊列
“);
if(threadNum>=maxthreadnum){//設置添加多少個進程
addThreadFlag=true;
this.stop();
}
}catch(Exception?e){
e.printStackTrace();
}
}
}
}
/**
?*?手動添加進程
?*?@param?work:進程對象
?*/
public?void?addThreadByHand(Work?work){
int?flag=addInSeqQueue(0?work);//把進程放入隊列
if(flag
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????647168??2009-10-07?21:22??操作系統原理課程設計報告.doc
?????文件???????8337??2009-06-30?14:26??src\math\Arithmetic.java
?????文件???????2867??2009-06-30?14:18??src\math\SeqQueue.java
?????文件???????1238??2009-04-25?12:06??src\math\Work.java
?????文件???????8068??2009-07-02?14:36??src\view\ControlView.java
?????文件??????12431??2009-07-03?13:22??src\view\View.java
?????文件????1937032??2009-07-03?12:32??多級反饋隊列調度算法.exe
?????目錄??????????0??2009-10-07?21:19??src\math
?????目錄??????????0??2009-10-07?21:19??src\view
?????目錄??????????0??2009-10-07?21:19??src
-----------?---------??----------?-----??----
??????????????2617141????????????????????10
評論
共有 條評論