Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Scheduler extends Thread{
- public Scheduler(){
- timeSlice = DEFAULT_TIME_SLICE;
- queue = new Circularlist();
- }
- public Scheduler(int quantum){
- timeSlice = quantum;
- queue = new Circularlist();
- }
- public addThread(Thread t) {
- t.setPriority(2);
- queue.additem(t);
- }
- private void schedulerSleep() {
- try{
- Thread.sleep(timeSlice );
- } catch (InterruptedException e){};
- }
- public void run(){
- Thread current;
- This.setpriority(6);
- While (true) {
- // get the next thread
- current = (Thread)qeue.getnext();
- if ( (current != null) && (current.isAlive()) ){
- current.setPriority(4);
- schedulerSleep();
- current.setPriority(2)
- }
- }
- }
- private CircularList queue;
- private int timeSlice;
- private static final int DEFAULT_TIME_SLICE = 1000;
- }
- public class TesScheduler{
- public static void main()String args[]) {
- Thread.currentThread().setpriority(Thread.Max_Priority);
- Schedular CPUSchedular = new Scheduler ();
- CPUSchedular.start()
- TestThread t1 = new TestThread("Thread 1");
- t1.start()
- CpuSchedular.addThread(t1);
- TestThread t2 = new TestThread("Thread 2");
- t2.start()
- CpuSchedular.addThread(t2);
- TestThread t3 = new TestThread("Thread 1");
- t3.start()
- CpuSchedular.addThread(t3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement