我现在要采用“基于时间片轮转法”调度算法对五个进程进行调度。 “轮转法”可以是简单轮转法、可变时间片轮转法,或多级反馈队列调度算法,但我是JAVA的初学者,不熟悉JAVA的编程,希望大家可以给予帮助,我编写了如下代码,可很多错误。
import java.util.*;
public class Test_thread
{
}
class Node
{
    Cpu_thread data=new Cpu_thread();
    Node next;
}
class Queue
{
    Node font=new Node();
    Node rear=font;
    public void enqueue(Cpu_thread e)
    {
        this.rear.data=e;
        this.rear=this.rear.next=new Node();
    }
    public Cpu_thread dequeue()
    {
        if(this.font==this.rear)
        {
            System.out.print("queue is empty!");
            System.exit(0);
            Cpu_thread re_thread=new Cpu_thread();
            return re_thread;
        }
        Node temp=this.font;
        this.font=this.font.next;
        Cpu_thread e=temp.data;
        temp=null;
        return e;
    }
}class Cpu_thread
{
    String name="";
    int time=0;
    Date nowtime=new Date();
    static Queue q=new Queue();
    Cpu_thread()
    {}
    Cpu_thread(String name)
    {
        this.time=this.nowtime.getSeconds();
        this.name=name;
        q.enqueue(this);
    }
    public void start()
    {
        Cpu_thread t=q.dequeue();
        t.run(t);
    }
    public void run(Cpu_thread t)
    {
        System.out.println();
        System.out.print("thread "+t.name+" run:");
           int i=655;
         int j=10;
    int count=0;
    while(j--!=0&&count<=100)
    {
        while(i--!=0&&count++<=100)
            {
             if(i==621)
             {
            this.sleep(t);
        }
        System.out.print("\t"+i);
        }
        System.out.println();
    }   
    }
    public void sleep(Cpu_thread sleep_t)
    {
        q.enqueue(sleep_t);
        while(true)
        {
            if(q.font.data==sleep_t) return;
            Cpu_thread t=q.dequeue();
            t.run(t);
        }
    }
}
class mainclass
{
    public static void main(String args[])
    {
        Cpu_thread t1=new Cpu_thread("1");
        Cpu_thread t2=new Cpu_thread("2");
        t1.start();
        t2.start();
    }
}