// This example is from the book _Java Threads_ by Scott Oaks and Henry Wong.
// Written by Scott Oaks and Henry Wong.
// Copyright (c) 1997 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or implied.
// Sample SimpleScheduler -- Chapter 6, p. 139.
public class SimpleScheduler extends Thread {
int timeslice;
public SimpleScheduler(int t) {
timeslice = t;
setPriority(Thread.MAX_PRIORITY);
setDaemon(true);
}
public void run() {
while (true)
try {
sleep(timeslice);
} catch (Exception e) {}
}
}
|