我现在要采用“基于时间片轮转法”调度算法对五个进程进行调度。 “轮转法”可以是简单轮转法、可变时间片轮转法,或多级反馈队列调度算法,但我是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();
}
}
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();
}
}
解决方案 »
- ??设计一个能计算百亿的计算器的思路
- 这两个简单的Socket,望高手指教,我都弄了一个早上了
- Which three will compile and rim without exception?
- 怎么判断读完整个文件的所有行啊
- 请教高手
- 用ASP.NET + C# + XSL + XML做了个东西,请大家帮忙测试,还有分拿!!
- 在jbuilder下编写的程序想在linux下运行,该怎么设置?急,急,急!!!!!!!
- 求救!!我现在可以在jdk环境下对applet所画的图进行存档,可在ie上不行,我该怎么做?
- 何为Automatic variable(自动变量)?
- 请大家推荐一本关于WEBLOGIC开发的好书!
- 急!我从mysql官方网上下载了mysql5.0.27-win32,安装到我机器上无法访问mysql服务器,报如下错!
- 英文版windows如何在SWING组件里显示中文
1)JAVA里有一个接口名字就叫Queue,如果你是要用队列,最好实现这个接口或者它的子类,或者你改一个名? 看着太不舒服了2)有好多错误?最好你自己把错误贴出来,或者说明什么错误.还有你最好加上点注释,并不是所有人都还记得什么是“基于时间片轮转法调度”的(当然,看名字也大约能想起来点意思的,但谁知道对不对呢),更不用说对照看看你这个是不是了?
你这么实际上跟叫人写个程序差不多!over!