FileDocCategorySizeDatePackage
PoolShrinker.javaAPI DocExample1515Thu Nov 08 00:22:36 GMT 2001com.ora.rmibook.chapter12.pool.finalthread

PoolShrinker

public class PoolShrinker extends Object implements Runnable

Fields Summary
private static final int
DEFAULT_TIME_TO_WAIT
private static final int
DEFAULT_TIME_INTERVAL
private ThreadedPool_Final
_owner
private int
_timeLeftUntilWeShrinkThePool
private boolean
_paused
Constructors Summary
public PoolShrinker(ThreadedPool_Final owner)

       
        _owner = owner;
        _timeLeftUntilWeShrinkThePool = DEFAULT_TIME_TO_WAIT;
    
Methods Summary
private synchronized voiddecrementClock()

        _timeLeftUntilWeShrinkThePool -= DEFAULT_TIME_INTERVAL;
        if (0 > _timeLeftUntilWeShrinkThePool) {
            _timeLeftUntilWeShrinkThePool = 0;
        }
    
public synchronized voidpause()

        _paused = true;
    
private synchronized voidresetClock()

        _timeLeftUntilWeShrinkThePool = DEFAULT_TIME_TO_WAIT;
    
public synchronized voidresume()

        _timeLeftUntilWeShrinkThePool = DEFAULT_TIME_TO_WAIT;
        _paused = false;
    
public voidrun()

        while (true) {
            try {
                Thread.sleep(DEFAULT_TIME_INTERVAL);
            } catch (InterruptedException e) {/* ignored*/
            }
            if (!_paused) {
                decrementClock();
                if (0 == _timeLeftUntilWeShrinkThePool) {
                    _owner.removeAnObject();
                    resetClock();
                }
            }
        }