📄 scheduler.java
字号:
package Utilities;public class Scheduler extends MyObject implements Runnable { private int timeSlice = 0; // milliseconds private boolean randomSlice = false; private boolean debug = false; private Thread t = null; public Scheduler(int timeSlice, boolean randomSlice, boolean debug) { super("Scheduler"); this.timeSlice = timeSlice; this.randomSlice = randomSlice; this.debug = debug; t = new Thread(this); t.setPriority(Thread.MAX_PRIORITY); t.setDaemon(true); t.start(); } public Scheduler(int timeSlice) { this(timeSlice, false, false); } public void run() { int napping; System.out.println(getName() + ": timeSlice=" + timeSlice + " randomSlice=" + randomSlice + " priority=" + t.getPriority()); while (true) { if (randomSlice) napping = 1 + (int) (2 * random(timeSlice)); else napping = timeSlice; nap(napping); // this highest-priority thread waking up sends the currently // executing thread to the end of the round-robin ready queue if (debug) System.out.println(getName() + " slicing at time " + age()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -