Escalonador

1 resposta
M

olá essas tres classes implementam um escalonador.;.porém não consigo mostrar o resultado com a saída do escalonador para que o usuário possa entender…alguem ajuda ai como posso fazer isso???

as classes são:

Counter

public class Counter extends Thread

{

int Count;
public Counter() {
	Count=0;
}

public Counter(int x) {
	Count=x;
}

public void run() {
	while(true)
	{
		Count++;
		try {
			sleep(10);
		} catch(InterruptedException e){}
	}
}

public int getCount() {
	return Count;
}

}

Scheduler

import java.util.*;

public class Scheduler extends Thread

{

private LinkedList queue;

private int timeSlice;

private static final int DEFAULT_TIME_SLICE = 1000;
public Scheduler() {

timeSlice = DEFAULT_TIME_SLICE;

queue = new LinkedList();

}
public Scheduler(int quantum) {

timeSlice = quantum;

queue = new LinkedList();

}
public void addThread(Thread t) {

t.setPriority(2);

queue.add(t);

}
private void schedulerSleep() {

try {

Thread.sleep(timeSlice);

} catch (InterruptedException e) {};

}

public void run() {
Thread current;

this.setPriority(6);

while (true) {
  current = (Thread)queue.removeFirst();
  if ((current != null) && (current.isAlive())) {
    current.setPriority(4);
    schedulerSleep();
    current.setPriority(2);
    //recoloca o thread no fim da fila
    addThread(current);
  }
}

}
}

TestScheduler

public class TestScheduler

{

public static void main(String args[]){

Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
Scheduler CPUScheduler = new Scheduler();
CPUScheduler.start();

Counter t1 = new Counter(100);
t1.start();
CPUScheduler.addThread(t1);

Counter t2 = new Counter(500);
t2.start();
CPUScheduler.addThread(t2);

Counter t3 = new Counter(900);
t3.start();
CPUScheduler.addThread(t3);

}
}

como faço a saída…monstrando o que o escalonador esta fazendo

1 Resposta

T

Já pensou em usar o System.out.println(“mensagem”);

Criado 16 de maio de 2007
Ultima resposta 20 de mai. de 2007
Respostas 1
Participantes 2