欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3769|回復: 2
打印 上一主題 下一主題
收起左側

關于時間輪轉調度的操作系統的JAVA程序設計

[復制鏈接]
跳轉到指定樓層
樓主
ID:574923 發表于 2019-6-30 10:56 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
《操作系統原理》是計算機科學與技術專業的,也是研究生入學考試中計算機專業綜合中所涉及的內容。理論性強,純粹的理論學習相對枯燥乏味,不易理解。通過設計,可加強學生對原理知識的理解。
二、設計的任務和要求

本次設計的題目是,時間片輪轉調度算法的模擬實現。要求在充分理解時間片輪轉調度算法原理的基礎上,編寫一個可視化的算法模擬程序。

具體任務如下:

1、根據需要,合理設計PCB結構,以適用于時間片輪轉調度算法;

2、設計模擬指令格式,并以文件形式存儲,程序能夠讀取文件并自動生成指令序列。

3、根據文件內容,建立模擬進程隊列,并能采用時間片輪轉調度算法對模擬進程進行調度。

任務要求:

1、進程的個數,進程的內容(即進程的功能序列)來源于一個進程序列描述文件。

2、需將調度過程輸出到一個運行日志文件。

3、開發平臺及語言不限。

4、要求設計一個Windows可視化應用程序。


3、需求分析
在計算機系統中,可能同時有數百個批處理作業存放在磁盤的作業隊列中,或者有數百個終端與主機相連接,這樣一來內存和處理器等資源便供不應求。如何從這些作業中挑選作業進入主存運行、如何在進程之間分配處理器時間,無疑是操作系統資源管理中的一個重要問題。因此引入處理器調度用來完成涉及處理器分配的工作,而其中的低級調度,執行分配CPU 的程序即分派程序(dispatcher),它是操作系統最為核心的部分,執行十分頻繁,低級調度策略優劣直接影響到整個系統的性能。
引入的目的是按照某種原則決定就緒隊列中的哪個進程或內核級線程能獲得處理器,并將處理器出讓給它進行工作。
4、總體設計
  

5、詳細設計與實現[含代碼和實現界面]

【代碼】
  1. package one;

  2. import java.awt.BorderLayout;
  3. import java.awt.EventQueue;

  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import javax.swing.JLabel;
  8. import javax.swing.JButton;
  9. import javax.swing.JFileChooser;

  10. import java.awt.event.ActionListener;
  11. import java.io.BufferedReader;
  12. import java.io.BufferedWriter;
  13. import java.io.File;
  14. import java.io.FileOutputStream;
  15. import java.io.FileReader;
  16. import java.io.FileWriter;
  17. import java.io.IOException;
  18. import java.util.ArrayList;
  19. import java.util.Date;
  20. import java.util.List;
  21. import java.util.Timer;
  22. import java.util.TimerTask;
  23. import java.awt.event.ActionEvent;
  24. import javax.swing.JTextField;
  25. import javax.swing.JList;
  26. import javax.swing.JOptionPane;
  27. import javax.swing.JTextPane;
  28. import javax.swing.JTextArea;


  29. class PCB{
  30.               public String pname;//進程名稱
  31.               public List<Instruction> pInstructions;//進程中指針列表
  32.               public int CurrentInstruction;//當前運行指令索引
  33.               PCB(){
  34.                             this.pInstructions = new ArrayList<Instruction>();
  35.               }
  36. }

  37. class Instruction{
  38.               public char IName;//指令類型
  39.               public double IRemainTime;//指令運行時間
  40.               public double IRuntime;////指令剩余運行時間
  41.               Instruction(){
  42.               }            
  43. }

  44. public class Test extends JFrame {

  45.               private JPanel contentPane;
  46.               JTextField text_timeslice = new JTextField();
  47.               JTextField textRunningProcess = new JTextField();
  48.               JTextPane text_ready_queue = new JTextPane();
  49.               JTextPane text_iwait_queue = new JTextPane();
  50.               JTextPane text_other_queue = new JTextPane();
  51.               JTextPane text_owait_queue = new JTextPane();
  52.               JTextField text_count = new JTextField();
  53.               Timer time = new Timer();
  54.               int count = 0;
  55.               int num = 0;
  56.               //創建各種隊列,用ArrayList實現
  57.               List<PCB> AllQueue = new ArrayList<PCB>();
  58.               List<PCB> ReadyQueue = new ArrayList<PCB>();
  59.               List<PCB> InputWaitingQueue = new ArrayList<PCB>();
  60.               List<PCB> OutputWaitingQueue = new ArrayList<PCB>();
  61.               List<PCB> PureWaitingQueue = new ArrayList<PCB>();
  62.             
  63.             
  64.             
  65.               /**
  66.               * Launch the application.
  67.               */
  68.               public static void main(String[] args) {
  69.                             EventQueue.invokeLater(new Runnable() {
  70.                                           public void run() {
  71.                                                         try {
  72.                                                                       Test frame = new Test();
  73.                                                                       frame.setVisible(true);
  74.                                                         } catch (Exception e) {
  75.                                                                       e.printStackTrace();
  76.                                                         }
  77.                                           }
  78.                             });
  79.               }

  80.               /**
  81.               * Create the frame.
  82.               */
  83.               public Test() {
  84.                             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  85.                             setBounds(100, 100, 956, 621);
  86.                             contentPane = new JPanel();
  87.                             contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  88.                             setContentPane(contentPane);
  89.                             contentPane.setLayout(null);
  90.                            
  91.                             JLabel label = new JLabel("\u65F6\u95F4\u7247:");
  92.                             label.setBounds(650, 53, 60, 18);
  93.                             contentPane.add(label);
  94.                            
  95.                             JButton btnOpenFile = new JButton("\u6253\u5F00\u6587\u4EF6");
  96.                             btnOpenFile.addActionListener(new ActionListener() {
  97.                                           public void actionPerformed(ActionEvent arg0) {
  98.                                                         JFileChooser chooser = new JFileChooser();
  99.                 if (chooser.showOpenDialog(btnOpenFile)==JFileChooser.APPROVE_OPTION) {//
  100.                     File file = chooser.getSelectedFile();
  101.                     textRunningProcess.setText(file.getName());
  102.                     readFile(file);
  103.                 };
  104.                                           }
  105.                             });
  106.                             btnOpenFile.setBounds(76, 49, 113, 27);
  107.                             contentPane.add(btnOpenFile);
  108.                            
  109.                             //開始調度按鈕事件
  110.                             JButton btnStartSchedule = new JButton("\u5F00\u59CB\u8C03\u5EA6");
  111.                             btnStartSchedule.addActionListener(new ActionListener() {
  112.                                           public void actionPerformed(ActionEvent e) {
  113.                                                         if(text_timeslice.getText().equals("")) {
  114.                                                                       JOptionPane.showMessageDialog(null,"請輸入時間片大小!");
  115.                                                         }
  116.                                                         else {
  117.                                                                       TimerTask task = new TimerTask() {
  118.                                                                                     public void run() {
  119.                                                                                                   RunOneTime();
  120.                                                                                                 
  121.                                                                                     }
  122.                                                                       };
  123.                                                                       btnStartSchedule.setEnabled(false);
  124.                                                                       time.schedule(task,new Date(),Long.parseLong(text_timeslice.getText()) );
  125.                                                         }
  126.                                           }
  127.                             });
  128.                             btnStartSchedule.setBounds(253, 49, 113, 27);
  129.                             contentPane.add(btnStartSchedule);
  130.                            
  131.                             //暫停調度按鈕事件
  132.                             JButton btnPauseSchedule = new JButton("\u6682\u505C\u8C03\u5EA6");
  133.                             btnPauseSchedule.addActionListener(new ActionListener() {
  134.                                           public void actionPerformed(ActionEvent e) {
  135.                                                         time.cancel();
  136.                                           }
  137.                             });
  138.                             btnPauseSchedule.setBounds(438, 49, 113, 27);
  139.                             contentPane.add(btnPauseSchedule);
  140.                            
  141.                            
  142.                             text_timeslice.setBounds(714, 50, 113, 24);
  143.                             contentPane.add(text_timeslice);
  144.                             text_timeslice.setColumns(10);
  145.                            
  146.                             JLabel label_1 = new JLabel("\u5F53\u524D\u8FD0\u884C\u8FDB\u7A0B:");
  147.                             label_1.setBounds(76, 108, 103, 18);
  148.                             contentPane.add(label_1);
  149.                            
  150.                            
  151.                             textRunningProcess.setBounds(76, 139, 103, 24);
  152.                             contentPane.add(textRunningProcess);
  153.                             textRunningProcess.setColumns(10);
  154.                            
  155.                             JLabel label_2 = new JLabel("\u5C31\u7EEA\u961F\u5217");
  156.                             label_2.setBounds(57, 205, 72, 18);
  157.                             contentPane.add(label_2);
  158.                            
  159.                             JLabel label_3 = new JLabel("\u8F93\u5165\u7B49\u5F85\u961F\u5217");
  160.                             label_3.setBounds(291, 205, 96, 18);
  161.                             contentPane.add(label_3);
  162.                            
  163.                             JLabel label_4 = new JLabel("\u8F93\u51FA\u7B49\u5F85\u961F\u5217");
  164.                             label_4.setBounds(497, 205, 96, 18);
  165.                             contentPane.add(label_4);
  166.                            
  167.                             JLabel label_5 = new JLabel("\u5176\u5B83\u7B49\u5F85\u961F\u5217");
  168.                             label_5.setBounds(721, 205, 96, 18);
  169.                             contentPane.add(label_5);
  170.                            
  171.                             text_ready_queue.setBounds(43, 236, 146, 205);
  172.                             contentPane.add(text_ready_queue);
  173.                            
  174.                            
  175.                             text_iwait_queue.setBounds(273, 236, 146, 205);
  176.                             contentPane.add(text_iwait_queue);
  177.                            
  178.                             text_owait_queue.setBounds(490, 236, 146, 205);
  179.                             contentPane.add(text_owait_queue);
  180.                            
  181.                            
  182.                             text_other_queue.setBounds(704, 236, 146, 205);
  183.                             contentPane.add(text_other_queue);
  184.                            

  185.                            
  186.                            
  187.                            
  188.               }
  189.               public void readFile(File file){//讀文件
  190.         BufferedReader bReader;
  191.         try {
  192.             bReader=new BufferedReader(new FileReader(file));
  193.             StringBuffer sBuffer=new StringBuffer();
  194.             String str;
  195.             while((str=bReader.readLine())!=null){
  196.                 sBuffer.append(str+'\n');
  197.                 switch(str.charAt(0)) {
  198.                 case 'P':
  199.                               PCB p = new PCB();
  200.                               p.pname = str;
  201.                               AllQueue.add(p);
  202.                               break;
  203.                 case 'C':
  204.                               Instruction ins1 = new Instruction();
  205.                               ins1.IRemainTime = Integer.parseInt(str.substring(1,3));
  206.                               ins1.IName = 'C';
  207.                               AllQueue.get(AllQueue.size()-1).pInstructions.add(ins1);
  208.                               break;
  209.                 case 'I':
  210.                               Instruction ins2 = new Instruction();
  211.                               ins2.IRemainTime = Integer.parseInt(str.substring(1,3));
  212.                               ins2.IName = 'I';
  213.                               AllQueue.get(AllQueue.size()-1).pInstructions.add(ins2);
  214.                               break;
  215.                 case 'O':
  216.                               Instruction ins3 = new Instruction();
  217.                               ins3.IRemainTime = Integer.parseInt(str.substring(1,3));
  218.                               ins3.IName = 'O';
  219.                               AllQueue.get(AllQueue.size()-1).pInstructions.add(ins3);
  220.                               break;
  221.                 case 'W':
  222.                               Instruction ins4 = new Instruction();
  223.                               ins4.IRemainTime = Integer.parseInt(str.substring(1,3));
  224.                               ins4.IName = 'W';
  225.                               AllQueue.get(AllQueue.size()-1).pInstructions.add(ins4);
  226.                               break;
  227.                 case 'H':
  228.                               Instruction ins5 = new Instruction();
  229.                               ins5.IRemainTime = Integer.parseInt(str.substring(1,3));
  230.                               ins5.IName = 'H';
  231.                               AllQueue.get(AllQueue.size()-1).pInstructions.add(ins5);
  232.                               break;
  233.                 }//switch                    
  234.             }//while


  235. //            String s1 = "";
  236. //            for(PCB p:ReadyQueue) {
  237. //                          s1 = s1+p.pname+"\r\n";
  238. //            }
  239. //            text_ready_queue.setText(s1);


  240.             //根據每個進程的首指令將進程分配到各個隊列中

  241. //            for(PCB p:AllQueue) {
  242. //                           switch(p.pInstructions.get(0).IName) {
  243. //                           case 'C':
  244. //                                         ReadyQueue.add(p);
  245. //                                         break;
  246. //                           case 'I':
  247. //                                         InputWaitingQueue.add(p);
  248. //                                         break;
  249. //                           case 'O':
  250. //                                         OutputWaitingQueue.add(p);
  251. //                                         break;
  252. //                           case 'W':
  253. //                                         PureWaitingQueue.add(p);
  254. //                                         break;
  255. //                           case 'H':
  256. //                                         break;
  257. //                           }
  258. //             }
  259. //           
  260.             String s1 = "";
  261.           for(PCB p:AllQueue) {
  262.                         s1 = s1+p.pname+"\r\n";
  263.           }
  264.           text_ready_queue.setText(s1);
  265.             //將界面正確顯示
  266. //            String s1 = "";
  267. //            for(PCB p:ReadyQueue) {
  268. //                          s1 = s1+p.pname+"\r\n";
  269. //            }
  270. //            text_ready_queue.setText(s1);
  271. //           
  272. //            String s2 = "";
  273. //            for(PCB p:InputWaitingQueue) {
  274. //                          s2 = s2+p.pname+"\r\n";
  275. //            }
  276. //            text_iwait_queue.setText(s2);
  277. //           
  278. //            String s3 = "";
  279. //            for(PCB p:OutputWaitingQueue) {
  280. //                          s3 = s3+p.pname+"\r\n";
  281. //            }
  282. //            text_owait_queue.setText(s3);
  283. //           
  284. //            String s4 = "";
  285. //            for(PCB p:PureWaitingQueue) {
  286. //                          s4 = s4+p.pname+"\r\n";
  287. //            }
  288. //            text_other_queue.setText(s4);

  289.         } catch (Exception e) {
  290.             // TODO: handle exception
  291.         }
  292.     }
  293.             
  294.             
  295.               //每隔一個時間間隔運行一次
  296.               public void RunOneTime() {
  297.                             int size = AllQueue.size();
  298.                             if(num<size) {
  299.                                           PCB p = AllQueue.get(num);
  300.                                           switch(p.pInstructions.get(0).IName) {
  301.                                  case 'C':
  302.                                                ReadyQueue.add(p);
  303.                                                break;
  304.                                  case 'I':
  305.                                                InputWaitingQueue.add(p);
  306.                                                break;
  307.                                  case 'O':
  308.                                                OutputWaitingQueue.add(p);
  309.                                                break;
  310.                                  case 'W':
  311.                                                PureWaitingQueue.add(p);
  312.                                                break;
  313.                                  case 'H':
  314.                                                break;
  315.                                  }
  316.                                           num++;
  317.                             }
  318.                            
  319.                             //只要有隊列不為空就一直調度
  320.                             if(ReadyQueue.size()!=0||InputWaitingQueue.size()!=0||OutputWaitingQueue.size()!=0||PureWaitingQueue.size()!=0) {
  321.                                          
  322.                                           //只有一個CPU,所以只能對就緒隊列的第一個PCB的運行指令時間進行減一操作
  323.                                           if(ReadyQueue.size()!=0) {
  324.                                                         if(ReadyQueue.get(0).pInstructions.get(ReadyQueue.get(0).CurrentInstruction).IRemainTime==0) {
  325.                                                                       ReadyQueue.get(0).CurrentInstruction++;
  326.                                                                       switch(ReadyQueue.get(0).pInstructions.get(ReadyQueue.get(0).CurrentInstruction).IName) {
  327.                                                                       case 'C':
  328.                                                                                     ReadyQueue.add(ReadyQueue.get(0));//先加再刪,ArrayList的好處,動態添加和刪除,[1,2,3]把1刪了再加,就是[2,,3,1]了
  329.                                                                                     ReadyQueue.remove(ReadyQueue.get(0));
  330.                                                                                     break;
  331.                                                                       case 'I':
  332.                                                                                     InputWaitingQueue.add(ReadyQueue.get(0));
  333.                                                                                     ReadyQueue.remove(ReadyQueue.get(0));
  334.                                                                                     break;
  335.                                                                       case 'O':
  336.                                                                                     OutputWaitingQueue.add(ReadyQueue.get(0));
  337.                                                                                     ReadyQueue.remove(ReadyQueue.get(0));
  338.                                                                                     break;
  339.                                                                       case 'W':
  340.                                                                                     PureWaitingQueue.add(ReadyQueue.get(0));
  341.                                                                                     ReadyQueue.remove(ReadyQueue.get(0));
  342.                                                                                     break;
  343.                                                                       case 'H':
  344.                                                                                     ReadyQueue.remove(ReadyQueue.get(0));
  345.                                                                                     break;
  346.                                                                       }
  347.                                                         }
  348.                                                         else {
  349.                                                                       ReadyQueue.get(0).pInstructions.get(ReadyQueue.get(0).CurrentInstruction).IRemainTime--;
  350.                                                                       textRunningProcess.setText(ReadyQueue.get(0).pname);
  351.                                                                       ReadyQueue.add(ReadyQueue.get(0));
  352.                                                                       ReadyQueue.remove(ReadyQueue.get(0));
  353.                                                         }
  354.                                           }
  355.                                          
  356.                                           //輸入等待隊列和輸出等待隊列以及其它等待隊列之所以采用for循環是因為任務書上說I/O設備不限,所以可以對這幾個隊列的每個PCB進行減一
  357.                                           if(InputWaitingQueue.size()!=0) {
  358.                                                         for(int i=0;i<=InputWaitingQueue.size()-1;i++) {
  359.                                                                       if(InputWaitingQueue.get(i).pInstructions.get(InputWaitingQueue.get(i).CurrentInstruction).IRemainTime==0) {
  360.                                                                                     InputWaitingQueue.get(i).CurrentInstruction++;
  361.                                                                                     switch(InputWaitingQueue.get(i).pInstructions.get(InputWaitingQueue.get(i).CurrentInstruction).IName) {
  362.                                                                                     case 'C':
  363.                                                                                                   ReadyQueue.add(InputWaitingQueue.get(i));
  364.                                                                                                   InputWaitingQueue.remove(InputWaitingQueue.get(i));
  365.                                                                                                   break;
  366.                                                                                     case 'I':
  367.                                                                                                   InputWaitingQueue.add(InputWaitingQueue.get(i));
  368.                                                                                                   InputWaitingQueue.remove(InputWaitingQueue.get(i));
  369.                                                                                                   break;
  370.                                                                                     case 'O':
  371.                                                                                                   OutputWaitingQueue.add(InputWaitingQueue.get(i));
  372.                                                                                                   InputWaitingQueue.remove(InputWaitingQueue.get(i));
  373.                                                                                                   break;
  374.                                                                                     case 'W':
  375.                                                                                                   PureWaitingQueue.add(InputWaitingQueue.get(i));
  376.                                                                                                   InputWaitingQueue.remove(InputWaitingQueue.get(i));
  377.                                                                                                   break;
  378.                                                                                     case 'H':
  379.                                                                                                   InputWaitingQueue.remove(InputWaitingQueue.get(i));
  380.                                                                                                   break;
  381.                                                                                     }
  382.                                                                       }
  383.                                                                       else {
  384.                                                                                     InputWaitingQueue.get(i).pInstructions.get(InputWaitingQueue.get(i).CurrentInstruction).IRemainTime--;
  385.                                                                       }
  386.                                                         }
  387.                                           }
  388.                                          
  389.                                           if(OutputWaitingQueue.size()!=0) {
  390.                                                         for(int i=0;i<=OutputWaitingQueue.size()-1;i++) {
  391.                                                                       if(OutputWaitingQueue.get(i).pInstructions.get(OutputWaitingQueue.get(i).CurrentInstruction).IRemainTime==0) {
  392.                                                                                     OutputWaitingQueue.get(i).CurrentInstruction++;
  393.                                                                                     switch(OutputWaitingQueue.get(i).pInstructions.get(OutputWaitingQueue.get(i).CurrentInstruction).IName) {
  394.                                                                                     case 'C':
  395.                                                                                                   ReadyQueue.add(OutputWaitingQueue.get(i));
  396.                                                                                                   OutputWaitingQueue.remove(OutputWaitingQueue.get(i));
  397.                                                                                                   break;
  398.                                                                                     case 'I':
  399.                                                                                                   InputWaitingQueue.add(OutputWaitingQueue.get(i));
  400.                                                                                                   OutputWaitingQueue.remove(OutputWaitingQueue.get(i));
  401.                                                                                                   break;
  402.                                                                                     case 'O':
  403.                                                                                                   OutputWaitingQueue.add(OutputWaitingQueue.get(i));
  404.                                                                                                   OutputWaitingQueue.remove(OutputWaitingQueue.get(i));
  405.                                                                                                   break;
  406.                                                                                     case 'W':
  407.                                                                                                   PureWaitingQueue.add(OutputWaitingQueue.get(i));
  408.                                                                                                   OutputWaitingQueue.remove(OutputWaitingQueue.get(i));
  409.                                                                                                   break;
  410.                                                                                     case 'H':
  411.                                                                                                   OutputWaitingQueue.remove(OutputWaitingQueue.get(i));
  412.                                                                                                   break;
  413.                                                                                     }
  414.                                                                       }
  415.                                                                       else {
  416.                                                                                     OutputWaitingQueue.get(i).pInstructions.get(OutputWaitingQueue.get(i).CurrentInstruction).IRemainTime--;
  417.                                                                       }
  418.                                                         }
  419.                                           }
  420.                                          
  421.                                           if(PureWaitingQueue.size()!=0) {
  422.                                                         for(int i=0;i<=PureWaitingQueue.size()-1;i++) {
  423.                                                                       if(PureWaitingQueue.get(i).pInstructions.get(PureWaitingQueue.get(i).CurrentInstruction).IRemainTime==0) {
  424.                                                                                     PureWaitingQueue.get(i).CurrentInstruction++;
  425.                                                                                     switch(PureWaitingQueue.get(i).pInstructions.get(PureWaitingQueue.get(i).CurrentInstruction).IName) {
  426.                                                                                     case 'C':
  427.                                                                                                   ReadyQueue.add(PureWaitingQueue.get(i));
  428.                                                                                                   PureWaitingQueue.remove(PureWaitingQueue.get(i));
  429.                                                                                                   break;
  430.                                                                                     case 'I':
  431.                                                                                                   InputWaitingQueue.add(PureWaitingQueue.get(i));
  432.                                                                                                   PureWaitingQueue.remove(PureWaitingQueue.get(i));
  433.                                                                                                   break;
  434.                                                                                     case 'O':
  435.                                                                                                   OutputWaitingQueue.add(PureWaitingQueue.get(i));
  436.                                                                                                   PureWaitingQueue.remove(PureWaitingQueue.get(i));
  437.                                                                                                   break;
  438.                                                                                     case 'W':
  439.                                                                                                   PureWaitingQueue.add(PureWaitingQueue.get(i));
  440.                                                                                                   PureWaitingQueue.remove(PureWaitingQueue.get(i));
  441.                                                                                                   break;
  442.                                                                                     case 'H':
  443.                                                                                                   PureWaitingQueue.remove(PureWaitingQueue.get(i));
  444.                                                                                                   break;
  445.                                                                                     }
  446.                                                                       }
  447.                                                                       else {
  448.                                                                                     PureWaitingQueue.get(i).pInstructions.get(PureWaitingQueue.get(i).CurrentInstruction).IRemainTime--;
  449.                                                                       }
  450.                                                         }
  451.                                           }
  452.                                          
  453.                                           //所有用到CPU資源的PCB都沒了就清空這個控件
  454.                                           if(ReadyQueue.size()==0) {
  455.                                                         textRunningProcess.setText("");
  456.                                           }
  457.                                          
  458.                                           //每進行一次調度就更新一次控件的信息
  459.                                           String str1 = "";
  460.                                           for(int i=0;i<ReadyQueue.size();i++) {
  461.                                                         str1 = str1+ReadyQueue.get(i).pname+"\r\n";
  462.                                           }
  463.                                           text_ready_queue.setText(str1);
  464.                                          
  465.                                           String str2 = "";
  466.                                           for(int i=0;i<InputWaitingQueue.size();i++) {
  467.                                                         str2 = str2+InputWaitingQueue.get(i).pname+"\r\n";
  468.                                           }
  469.                                           text_iwait_queue.setText(str2);
  470.                                          
  471.                                           String str3 = "";
  472.                                           for(int i=0;i<OutputWaitingQueue.size();i++) {
  473.                                                         str3 = str3+OutputWaitingQueue.get(i).pname+"\r\n";
  474.                                           }
  475.                                           text_owait_queue.setText(str3);
  476.                                          
  477.                                           String str4 = "";
  478.                                           for(int i=0;i<PureWaitingQueue.size();i++) {
  479.                                                         str4 = str4+PureWaitingQueue.get(i).pname+"\r\n";
  480.                                           }
  481.                                           text_other_queue.setText(str4);
  482.                                          
  483.                                           count++;
  484.                                          
  485.                                           String schedule = "第"+String.valueOf(count)+"次調度情況:\r\n"+"就緒隊列:\r\n"+str1+"\r\n"+"輸入等待隊列:\r\n"+str2+"\r\n"
  486.                                                                                                                                             +"輸出等待隊列:\r\n"+str3+"\r\n"+"其它等待隊列:\r\n"+str4+"\r\n";
  487.                                           writeFile(schedule);
  488.                             }
  489.                             else {
  490.                                           JOptionPane.showMessageDialog(null, "調度結束!");
  491.                                           time.cancel();
  492.                             }
  493.               }
  494.               public static void writeFile(String text) {
  495.         try {
  496.             File writeName = new File("F:\\Java201903\\output.txt"); // 相對路徑,如果沒有則要建立一個新的output.txt文件
  497. //            writeName.createNewFile(); // 創建新文件,有同名的文件的話直接覆蓋
  498.             try (FileWriter writer = new FileWriter(writeName,true);//追加
  499.                  BufferedWriter out = new BufferedWriter(writer)
  500.             ) {
  501.                 out.write(text);
  502.                 out.flush(); // 把緩存區內容壓入文件
  503.             }
  504.         } catch (IOException e) {
  505.             e.printStackTrace();
  506.         }
  507.     }

  508. }
復制代碼

這次課設我提前有嘗試自己來實現,查了一些網上的思路,書本上的算法,然后就試著慢慢寫,遇到不懂的問了同學和老師。收獲很多,在隊列中用add和remove兩個函數來實現。JAVA的好處是很多算法都直接調用就行了,對我很友好。代碼不是很簡潔,應該試著再改一下的。我覺得我應該花更多的時間在代碼的學習和運用上。

以上內容Word格式文檔51黑下載地址:
操作系統課程設計報告.doc (335 KB, 下載次數: 25)


評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂1 踩
回復

使用道具 舉報

無效樓層,該帖已經被刪除
板凳
ID:934927 發表于 2021-6-9 18:37 | 只看該作者
The public type Test must be defined in its own file 樓主您好 我直接復制您的代碼報錯了 請問源文件還在嗎
回復

使用道具 舉報

地板
ID:1058238 發表于 2022-12-19 09:58 | 只看該作者
wizardbcat 發表于 2021-6-9 18:37
The public type Test must be defined in its own file 樓主您好 我直接復制您的代碼報錯了 請問源文件還 ...

把你的包名改成one就好了
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表