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

AlarmClock

public class AlarmClock extends Object

Fields Summary
private static final int
MAX_CAPACITY
private static final int
UNUSED
private static final int
NOROOM
private Sleeper[]
sleepers
private long[]
sleepFor
Constructors Summary
public 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 s, long time)

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

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