【南邮操作系统实验】页面置换算法(FIFO、LRU、OPT)图形化界面(JavaFx)

sb.append(“本次页面走向,页框中已经存在!\n”);

sb.append(“目前物理页框中页面走向为:”);

for (Integer i : pageFrame) {

// System.out.print(i + " ");

sb.append(i + " ");

}

sb.append(“\n---------------------------------------\n”);

count++;

continue;

}

// 判断物理页框有无空位

for (int i = 0 ; i < frameNum ; i++){

if (pageFrame[i] == null){

isEmpty = true;

break;

}else{

isEmpty = false;

}

}

// 本次页面走向,物理页框中不存在,且有空位,按顺序放入

if (isExist == false && isEmpty == true){

for (int i = 0; i < frameNum; i++) {

if (pageFrame[i] == null) { // 物理页框中有空位则放入

pageFrame[i] = page[count];

break; // 从头开始找,找到一个空位即可

}

}

}

// 实现 FIFO 算法

// 本次页面走向,物理页框中不存在,且物理页框中没有空位了

if (isExist == false && isEmpty == false){

// 此时的 pageFrame[helpNum%frameNum] 为淘汰页面

stack.push(pageFrame[helpNum%frameNum]); // 淘汰页面入栈

// System.out.println(“本次淘汰页面:” + pageFrame[helpNum%frameNum]);

sb.append(“本次淘汰页面:” + pageFrame[helpNum%frameNum] + “\n”);

pageFrame[helpNum%frameNum] = page[count]; // 先进先出

helpNum++;

}

if (isMiss == true){ // 计算缺页次数

pageMissNum++;

}

// System.out.print(“目前物理页框中页面走向为:”);

sb.append(“目前物理页框中页面走向为:”);

for (Integer i : pageFrame) {

// System.out.print(i + " ");

sb.append(i + " ");

}

// System.out.println();

sb.append(“\n---------------------------------------\n”);

count++;

}

// System.out.println();

sb.append(“\n”);

System.out.println(“缺页次数:” + pageMissNum + “次”);

System.out.println("一共调用: " + pageNum + “次”);

System.out.println(“缺页中断率:” + pageMissNum1.0/pageNum100 + “%” );

System.out.print(“淘汰页面:”);

for (Integer integer : stack) {

System.out.print(integer + " ");

}

return sb.toString();

}

public static void main(String[] args) {

FIFO fifo = new FIFO();

String s = fifo.fifoRun(3, “2 3 2 1 5 2 4 5 3 2 5 2”);

System.out.println(s);

}

}

LRU


package com.yusael.pagereplace;

import java.util.Stack;

public class LRU {

public int frameNum; // 分配给该作业的物理页框数

public Integer[] pageFrame; // 物理页框

public int pageNum; // 作业的页面走向总次数

public Integer[] pages; // 作业的页面走向

public Stack stack = new Stack<>(); // 存放淘汰页面的栈

public int pageMissNum = 0; // 缺页次数</

  • 5
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java实现秒杀系统@Controller @RequestMapping("seckill")//url:/模块/资源/{id}/细分 /seckill/list public class SeckillController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private SeckillService seckillService; @RequestMapping(value="/list",method = RequestMethod.GET) public String list(Model model){ //获取列表页 List list=seckillService.getSeckillList(); model.addAttribute("list",list); //list.jsp+model = ModelAndView return "list";//WEB-INF/jsp/"list".jsp } @RequestMapping(value = "/{seckillId}/detail",method = RequestMethod.GET) public String detail(@PathVariable("seckillId") Long seckillId, Model model){ if (seckillId == null){ return "redirect:/seckill/list"; } Seckill seckill = seckillService.getById(seckillId); if (seckill == null){ return "forward:/seckill/list"; } model.addAttribute("seckill",seckill); return "detail"; } //ajax json @RequestMapping(value = "/{seckillId}/exposer", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @ResponseBody public SeckillResult exposer(@PathVariable("seckillId") Long seckillId){ SeckillResult result; try { Exposer exposer =seckillService.exportSeckillUrl(seckillId); result = new SeckillResult(true,exposer); } catch (Exception e) { logger.error(e.getMessage(),e); result = new SeckillResult(false,e.getMessage()); } return result; } @RequestMapping(value = "/{seckillId}/{md5}/execution", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"} ) @ResponseBody public SeckillResult execute(@PathVariable("seckillId")Long seckillId,

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值