FileDocCategorySizeDatePackage
AlarmClock.javaAPI DocExample1127Tue Dec 12 18:58:10 GMT 2000None

AlarmClock

public class AlarmClock extends Object

Fields Summary
static final int
MAX_CAPACITY
static final int
UNUSED
static final int
NOROOM
private Sleeper[]
sleepers
long[]
sleepFor
Constructors Summary
AlarmClock()


      
	for (int i = 0; i < MAX_CAPACITY; i++)
	    sleepFor[i] = UNUSED;
    
Methods Summary
private synchronized intfindNextSlot()

        for (int i = 0; i < MAX_CAPACITY; i++) {
            if (sleepFor[i] == UNUSED)
                return i;
        }
        return NOROOM;
    
public synchronized booleanletMeSleepFor(Sleeper theSleeper, long time)

        int index = findNextSlot();
        if (index == NOROOM) {
            return false;
        } else {
            sleepers[index] = theSleeper;
            sleepFor[index] = time;
            new AlarmThread(this, index).start();
            return true;
        }
    
synchronized voidwakeUpSleeper(int sleeperIndex)

        sleepers[sleeperIndex].wakeUp();
        sleepers[sleeperIndex] = null;
        sleepFor[sleeperIndex] = UNUSED;