Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## net.sourceforge.jtds.util
Class TimerThread

    java.lang.Object
      |
      +--java.lang.Thread
            |
            +--net.sourceforge.jtds.util.TimerThread

All Implemented Interfaces:
  java.lang.Runnable

public class TimerThread
extends java.lang.Thread

Simple timer class used to implement login and query timeouts.

This thread runs as a Daemon thread to ensure that the java VM will exit correctly when normal execution is complete.

It provides both a singleton implementation and a default constructor for the case when more than one timer thread is desired.

Version:
  $Id: TimerThread.java,v 1.5 2005/04/28 14:29:31 alin_sinpalean Exp $
Author:
  Alin Sinpalean, Mike Hutchinson

Inner Class Summary
`static interface` | `TimerThread.TimerListener` Interface to be implemented by classes that request timer services.
`private static class` | `TimerThread.TimerRequest` Internal class associating a login or query timeout value with a target `TimerListener`.

Field Summary
`private static TimerThread` | `instance` Singleton instance.
`private long` | `nextTimeout` Time when the first request time out should occur.
`private java.util.LinkedList` | `timerList` List of `TimerRequest`s to execute, ordered by time.

Fields inherited from class java.lang.Thread
`contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ`

Constructor Summary
`TimerThread()` Construct a new `TimerThread` instance.

Method Summary
`boolean` | `cancelTimer(java.lang.Object handle)` Remove a redundant timer before it expires.
`static TimerThread` | `getInstance()` Singleton getter.
`boolean` | `hasExpired(java.lang.Object handle)` Check whether a timer has expired.
`void` | `run()` Execute the `TimerThread` main loop.
`java.lang.Object` | `setTimer(int timeout, TimerThread.TimerListener l)` Add a timer request to the queue.
`private void` | `updateNextTimeout()` Internal method that updates the value of `nextTimeout`.

Methods inherited from class java.lang.Thread
`, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### instance

    private static TimerThread instance

  Singleton instance.

### timerList

    private final java.util.LinkedList timerList

  List of `TimerRequest`s to execute, ordered by time.

### nextTimeout

    private long nextTimeout

  Time when the first request time out should occur.

Constructor Detail

### TimerThread

    public TimerThread()

  Construct a new `TimerThread` instance.

Method Detail

### getInstance

    public static TimerThread getInstance()

  Singleton getter.

### run

    public void run()

  Execute the `TimerThread` main loop.
  Overrides:
    `run` in class `java.lang.Thread`

### setTimer

    public java.lang.Object setTimer(int timeout,
                                     TimerThread.TimerListener l)

  Add a timer request to the queue.

  The queue is ordered by time so that the head of the list is always the first timer to expire.
  Parameters:
    `timeout` - the interval in milliseconds after which the timer will expire
    `l` - `TimerListener` to be notified on timeout
  Returns:
    a handle to the timer request, that can later be used with `cancelTimer`

### cancelTimer

    public boolean cancelTimer(java.lang.Object handle)

  Remove a redundant timer before it expires.
  Parameters:
    `handle` - handle to the request to be removed from the queue (a `TimerRequest` instance)
  Returns:
    `true` if timer had not expired

### hasExpired

    public boolean hasExpired(java.lang.Object handle)

  Check whether a timer has expired.
  Parameters:
    `handle` - handle to the request to be checked for expiry (a `TimerRequest` instance)
  Returns:
    `true` if timer has expired

### updateNextTimeout

    private void updateNextTimeout()

  Internal method that updates the value of `nextTimeout`.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Generated on November 8 2005