자바 고수님들 1.2번에러좀 고쳐주세요^^
핑크빛입술
1.번
public class TestScheduler
{
public static void main (String args[]) {
Thread.currentThread() .setPriority(Thread.MAX_PRIORITY);
Scheduler CPUScheduler=new Scheduler ();
CPUScheduler.start();
TestThread t1=new TestThread(Thread 1);
t1.start();
CPUScheduler.addThread(t1);
TestThread t2=new TestThread(Thread 2);
t2.start();
CPUScheduler.addThread(t2);
TestThread t3=new TestThread(Thread 3);
t3.start();
CPUScheduler.addThread(t3);
}
}
2.번
public class Scheduler extends Thread
{
public Scheduler(){
timeSlice=DEFAULT_TIME.SLICE;
queue=new CircularList();
}
public Scheduler(int quantum){
timeSlice=quantum;
queue=new CircularList();
}
public void addThread(Thread t){
t.setPriority(2);
queue.addItem(t);
}
private void schedulerSleep(){
try{
Thread.sleep(timeSlice);
}catch (InterruptedExeption e){};
}
public void run(){
Thread current;
this.setPriority(6);
while(true){
current=(Thread)queue.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;
}
-
하양이
제가 지금 배우는 책이랑 똑같네요...소스가....ㅋ
-
옆집꼬마야
class TestThread extends Thread
{
private String name;
public TestThread(String id) {
name = id;
}
public void run() {
\t/*
\t * The thread does something
\t **/
while (true) {
\tfor (int i = 0; i 500000; i++)
\t\t;
\tSystem. -
찬솔나라
testthread의 클래스 정의가 안 되어 있네요..