采用JavaSwing+多线程+操作系统进程调度算法GUI动画实现进程调用过程程序,系统采用多层C/S软件架构,采用javaSwing窗口开发技术实现进程调度动画界面,实现JAVA2D模拟实现先入先出(FIFO),时间片轮转,优先级调度等操作系统进程调度算法整体逻辑过程。系统主要实现技术包括,java2D动画,java多线程控制,javaswing,操作系统核心调度算法实现等。
一、程序设计
本次基于JavaSwing+多线程+操作系统进程调度算法GUI动画实现进程调用过程程序,主要内容涉及:
主要功能模块:进程管理、进程创建、进程调度动画模拟、进程调度算实现,系统多线程控制,分析统计等等
主要包含技术:java,swing,java多线程,操作系统原理,进程调度算法,java2D,GUI
主要包含算法:操作系统进程调度算法,先入先出(FIFO),时间片轮转,优先级调度等
二、效果实现
进程调度
其他效果省略
三、核心代码
1.时间片轮转算法
本系统程序时间片轮转模块主要实现对操作系统进程调用过程采用时间片轮转算法实现,控制GUI界面动画刷新与数据更新绑定,记录进程调度时间及效果等。
// 采用时间片轮转算法模拟进程调度 public static void RoundRobin(List<ProcessModel> list) { // 循环模拟的轮转下标 // int round = 0; // 最小轮转次数 int minRoundRobinCount = 0; // 实际循环执行次数 int actualRoundRobinCount = 0; for (int i = 0; i < list.size(); i++) { minRoundRobinCount += list.get(i).getProcessServiceTime(); } while (true) { try { actualRoundRobinCount++; // 采用随机数模拟轮转 ProcessModel process = list.get(new Random().nextInt(list .size())); // 采用round执行循环模拟 // if (round >= list.size()) { // round = 0; // } // ProcessModel process = list.get(round++); int serviceTime = process.getProcessServiceTime(); int currentTime = process.getProcessCurrentTime(); if (currentTime < serviceTime) { Thread.sleep(1000); process.setProcessCurrentStatus("Running"); process.setProcessCurrentTime(process .getProcessCurrentTime() + 1); // 刷新要显示的数据 SystemController.getUserTable().showTableData(list); SystemController.getPanelProcess().requestFocus(); SystemController.getPanelProcess().repaint(); if (process.getProcessCurrentTime() == process .getProcessServiceTime()) { process.setProcessCurrentStatus("Finished"); // 刷新要显示的数据 SystemController.getUserTable().showTableData(list); SystemController.getPanelProcess().requestFocus(); SystemController.getPanelProcess().repaint(); } else { process.setProcessCurrentStatus("waitting"); } } if (actualRoundRobinCount >= minRoundRobinCount && isOver(list)) { break; } } catch (InterruptedException e) { e.printStackTrace(); } } }
<span class="token comment">// 判断进程队列中是否还有未完成的进程</span> <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">boolean</span> <span class="token function">isOver</span><span class="token punctuation">(</span><span class="token class-name">List</span><span class="token generics"><span class="token punctuation"><</span><span class="token class-name">ProcessModel</span><span class="token punctuation">></span></span> list2<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span> <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator"><</span> list2<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span> <span class="token class-name">ProcessModel</span> processModel <span class="token operator">=</span> list2<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>processModel<span class="token punctuation">.</span><span class="token function">getProcessCurrentTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator"><</span> processModel <span class="token punctuation">.</span><span class="token function">getProcessServiceTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span> <span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
2.先入先出(FIFO)算法
本系统程序FIFO模块主要实现对操作系统进程调用过程采用FIFO算法实现,控制GUI界面动画刷新与数据更新绑定,记录进程调度时间及效果等。
/**
* 采用先来先服务算法模拟进程调度
*
* @param list
*/
public static void FcFs(List<ProcessModel> list) {
for (int i = 0; i < list.size(); i++) {
try {
// 从进程队列中拿到一个进程(按照创建的顺序)
ProcessModel processModel = list.get(i);
for (int j = 0; j < processModel.getProcessServiceTime(); j++) {
if ("Finished".equals(processModel
.getProcessCurrentStatus())) {
continue;
}
// 程序暂停一秒
Thread.sleep(1000);
processModel.setProcessCurrentStatus("Running");
processModel.setProcessCurrentTime(processModel
.getProcessCurrentTime() + 1);
// 刷新要显示的数据
SystemController.getUserTable().showTableData(list);
SystemController.getPanelProcess().requestFocus();
SystemController.getPanelProcess().repaint();
if (processModel.getProcessCurrentTime() == processModel
.getProcessServiceTime()) {
processModel.setProcessCurrentStatus("Finished");
// 刷新要显示的数据
SystemController.getUserTable().showTableData(list);
SystemController.getPanelProcess().requestFocus();
SystemController.getPanelProcess().repaint();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}