public Stopper(Workpile w, int d) {
workpile = w;
delay = d;
}
public void run() {
InterruptibleThread.sleep(delay*1000);
System.out.println("Stopping...");
synchronized (workpile) {
workpile.stop = true;
workpile.notifyAll();
}
//  for (int i=0; i < Server.nConsumers; i++)
//
Server.consumers[i].interrupt();
for (int i = 0; i < Server.nProducers; i++)
Server.producers[i].interrupt();
Server.acceptor.interrupt();
}
}
//
ServerInterruptible/Workpile.java
/*
A Workpile is a container for a list of Requests and the
synchronization
variables that protect its internals. The synchronization and
management
of the list is EXTERNAL to the class because I want to illustrate
its
use in the producer/consumer code  (and to make this program as
similar
as possible to the C version).
The Workpile is constructed on top of a List (see Extensions). It
could
equally well be implemented by subclassing Vector; unfortunately
Vector
is HORRIBLY inefficient for lists.
*/
import java.io.*;
import Extensions.*;
public class Workpile {
List
list = List.nil;
int
length = 0;
static int max = 10;
boolean
stop = false;
public Workpile(int i) {
max = i;
}
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks
Home