Java Doc for HsqlTimer.java in  » Database-DBMS » hsql » org » hsqldb » lib » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » hsql » org.hsqldb.lib 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.hsqldb.lib.HsqlTimer

HsqlTimer
final public class HsqlTimer implements ObjectComparator,ThreadFactory(Code)
Facility to schedule tasks for future execution in a background thread.

Tasks may be scheduled for one-time execution or for repeated execution at regular intervals, using either fixed rate or fixed delay policy.

This class is a JDK 1.1 compatible implementation required by HSQLDB both because the java.util.Timer class is available only in JDK 1.3+ and because java.util.Timer starves least recently added tasks under high load and fixed rate scheduling, especially when the average actual task duration is greater than the average requested task periodicity.

An additional (minor) advantage over java.util.Timer is that this class does not retain a live background thread during periods when the task queue is empty.
author:
   boucherb@users
version:
   1.8.0.3
since:
   1.7.2


Inner Class :protected class TaskRunner implements Runnable
Inner Class :protected class Task
Inner Class :protected static class TaskQueue extends HsqlArrayHeap

Field Summary
protected volatile  booleanisShutdown
     Whether this timer should disallow all further processing.
static  intnowCount
    
final protected  TaskQueuetaskQueue
     The priority queue for the scheduled tasks.
final protected  TaskRunnertaskRunner
     The inner runnable that executes tasks in the background thread.
protected  ThreadtaskRunnerThread
     The background thread.
final protected  ThreadFactorythreadFactory
     The factory that procduces the background threads.

Constructor Summary
public  HsqlTimer()
     Constructs a new HsqlTimer using the default thread factory implementation.
public  HsqlTimer(ThreadFactory threadFactory)
     Constructs a new HsqlTimer. Uses the specified thread factory implementation.
Parameters:
  threadFactory - the ThreadFactory used to produce this timer'sbackground threads.

Method Summary
protected  TaskaddTask(long first, Runnable runnable, long period, boolean relative)
     Adds to the task queue a new Task object encapsulating the supplied Runnable and scheduling arguments.
public static  voidcancel(Object task)
     Causes the task referenced by the supplied argument to be cancelled.
protected synchronized  voidclearThread()
     Sets the background thread to null.
public  intcompare(Object a, Object b)
     Required to back the priority queue for scheduled tasks.
public static  DategetLastScheduled(Object task)
     Retrieves the last time the referenced task was executed, as a Date object.
public static  DategetNextScheduled(Object task)
     Retrieves the next time the referenced task is due to be executed, as a Date object.
public synchronized  ThreadgetThread()
     Retrieves the background execution thread.
public static  booleanisCancelled(Object task)
     Retrieves whether the specified argument references a cancelled task.
public static  booleanisFixedDelay(Object task)
     Retrieves whether the specified argument references a task scheduled periodically using fixed delay scheduling.
public static  booleanisFixedRate(Object task)
     Retrieves whether the specified argument references a task scheduled periodically using fixed rate scheduling.
public static  booleanisPeriodic(Object task)
     Retrieves whether the specified argument references a task scheduled for periodic execution.
public  ThreadnewThread(Runnable runnable)
     Default ThreadFactory implementation.
protected  TasknextTask()
     Retrieves the next task to execute, or null if this timer is shutdown, the current thread is interrupted, or there are no queued tasks.
public synchronized  voidrestart()
     (Re)starts background processing of the task queue.
public  ObjectscheduleAfter(long delay, Runnable runnable)
     Causes the specified Runnable to be executed once in the background after the specified delay.
Parameters:
  delay - in milliseconds
Parameters:
  runnable - the Runnable to execute.
public  ObjectscheduleAt(Date date, Runnable runnable)
     Causes the specified Runnable to be executed once in the background at the specified time.
Parameters:
  date - time at which to execute the specified Runnable
Parameters:
  runnable - the Runnable to execute.
public  ObjectschedulePeriodicallyAfter(long delay, long period, Runnable runnable, boolean relative)
     Causes the specified Runnable to be executed periodically in the background, starting after the specified delay.
public  ObjectschedulePeriodicallyAt(Date date, long period, Runnable runnable, boolean relative)
     Causes the specified Runnable to be executed periodically in the background, starting at the specified time.
public static  ObjectsetPeriod(Object task, long period)
     Sets the periodicity of the designated task to a new value.
public synchronized  voidshutdown()
     Shuts down this timer after the current task (if any) completes.
public synchronized  voidshutdownImmediately()
     Shuts down this timer immediately, interrupting the wait state associated with the current head of the task queue or the wait state internal to the currently executing task, if any such state is currently in effect. After this call, the timer has permanently entered the shutdown state; attempting to schedule any new task or directly restart this timer will result in an IllegalStateException.

Field Detail
isShutdown
protected volatile boolean isShutdown(Code)
Whether this timer should disallow all further processing. Once set true, stays true forever.



nowCount
static int nowCount(Code)
stats var



taskQueue
final protected TaskQueue taskQueue(Code)
The priority queue for the scheduled tasks.



taskRunner
final protected TaskRunner taskRunner(Code)
The inner runnable that executes tasks in the background thread.



taskRunnerThread
protected Thread taskRunnerThread(Code)
The background thread.



threadFactory
final protected ThreadFactory threadFactory(Code)
The factory that procduces the background threads.




Constructor Detail
HsqlTimer
public HsqlTimer()(Code)
Constructs a new HsqlTimer using the default thread factory implementation.



HsqlTimer
public HsqlTimer(ThreadFactory threadFactory)(Code)
Constructs a new HsqlTimer. Uses the specified thread factory implementation.
Parameters:
  threadFactory - the ThreadFactory used to produce this timer'sbackground threads. If null, the default implementation suppliedby this class will be used.




Method Detail
addTask
protected Task addTask(long first, Runnable runnable, long period, boolean relative)(Code)
Adds to the task queue a new Task object encapsulating the supplied Runnable and scheduling arguments.
Parameters:
  first - the time of the task's first execution
Parameters:
  runnable - the Runnable to execute
Parameters:
  period - the task's periodicity
Parameters:
  relative - if true, use fixed rate else use fixed delay scheduling an opaque reference to the internal task



cancel
public static void cancel(Object task)(Code)
Causes the task referenced by the supplied argument to be cancelled. If the referenced task is currently executing, it will continue until finished but will not be rescheduled.
Parameters:
  task - a task reference



clearThread
protected synchronized void clearThread()(Code)
Sets the background thread to null.



compare
public int compare(Object a, Object b)(Code)
Required to back the priority queue for scheduled tasks.
Parameters:
  a - the first Task
Parameters:
  b - the second Task 0 if equal, < 0 if a < b, > 0 if a > b



getLastScheduled
public static Date getLastScheduled(Object task)(Code)
Retrieves the last time the referenced task was executed, as a Date object. If the task has never been executed, null is returned.
Parameters:
  task - a task reference the last time the referenced task was executed; null if never



getNextScheduled
public static Date getNextScheduled(Object task)(Code)
Retrieves the next time the referenced task is due to be executed, as a Date object. If the referenced task is cancelled, null is returned.
Parameters:
  task - a task reference the next time the referenced task is due to be executed



getThread
public synchronized Thread getThread()(Code)
Retrieves the background execution thread.

null is returned if there is no such thread.

the current background thread (may be null)




isCancelled
public static boolean isCancelled(Object task)(Code)
Retrieves whether the specified argument references a cancelled task.
Parameters:
  task - a task reference true if referenced task is cancelled



isFixedDelay
public static boolean isFixedDelay(Object task)(Code)
Retrieves whether the specified argument references a task scheduled periodically using fixed delay scheduling.
Parameters:
  task - a task reference true if the reference is scheduled using a fixed delay



isFixedRate
public static boolean isFixedRate(Object task)(Code)
Retrieves whether the specified argument references a task scheduled periodically using fixed rate scheduling.
Parameters:
  task - a task reference true if the task is scheduled at a fixed rate



isPeriodic
public static boolean isPeriodic(Object task)(Code)
Retrieves whether the specified argument references a task scheduled for periodic execution.
Parameters:
  task - a task reference true if the task is scheduled for periodic execution



newThread
public Thread newThread(Runnable runnable)(Code)
Default ThreadFactory implementation.

Contructs a new Thread from the designated runnable, sets its name to "HSQLDB Timer @" + Integer.toHexString(hashCode()), and sets it as a daemon thread.


Parameters:
  runnable - used to construct the new Thread. a new Thread constructed from the designated runnable.




nextTask
protected Task nextTask()(Code)
Retrieves the next task to execute, or null if this timer is shutdown, the current thread is interrupted, or there are no queued tasks. the next task to execute, or null



restart
public synchronized void restart() throws IllegalStateException(Code)
(Re)starts background processing of the task queue.
throws:
  IllegalStateException - if this timer is shut down.
See Also:   HsqlTimer.shutdown()
See Also:   HsqlTimer.shutdownImmediately()



scheduleAfter
public Object scheduleAfter(long delay, Runnable runnable) throws IllegalArgumentException(Code)
Causes the specified Runnable to be executed once in the background after the specified delay.
Parameters:
  delay - in milliseconds
Parameters:
  runnable - the Runnable to execute. opaque reference to the internal task
throws:
  IllegalArgumentException - if runnable is null



scheduleAt
public Object scheduleAt(Date date, Runnable runnable) throws IllegalArgumentException(Code)
Causes the specified Runnable to be executed once in the background at the specified time.
Parameters:
  date - time at which to execute the specified Runnable
Parameters:
  runnable - the Runnable to execute. opaque reference to the internal task
throws:
  IllegalArgumentException - if date or runnable is null



schedulePeriodicallyAfter
public Object schedulePeriodicallyAfter(long delay, long period, Runnable runnable, boolean relative) throws IllegalArgumentException(Code)
Causes the specified Runnable to be executed periodically in the background, starting after the specified delay. opaque reference to the internal task
Parameters:
  period - the cycle period
Parameters:
  relative - if true, fixed rate sheduling else fixed delay scheduling
Parameters:
  delay - in milliseconds
Parameters:
  runnable - the Runnable to execute.
throws:
  IllegalArgumentException - if runnable is null or period is <= 0



schedulePeriodicallyAt
public Object schedulePeriodicallyAt(Date date, long period, Runnable runnable, boolean relative) throws IllegalArgumentException(Code)
Causes the specified Runnable to be executed periodically in the background, starting at the specified time. opaque reference to the internal task
Parameters:
  period - the cycle period
Parameters:
  relative - if true, fixed rate sheduling else fixed delay scheduling
Parameters:
  date - time at which to execute the specified Runnable
Parameters:
  runnable - the Runnable to execute
throws:
  IllegalArgumentException - if date or runnable is null, orperiod is <= 0



setPeriod
public static Object setPeriod(Object task, long period)(Code)
Sets the periodicity of the designated task to a new value.

If the designated task is cancelled or the new period is identical to the task's current period, then this invocation has essentially no effect and the submitted object is returned.

Otherwise, if the new period is greater than the designated task's current period, then a simple assignment occurs and the submittted object is returned.

If neither case holds, then the designated task is cancelled and a new, equivalent task with the new period is scheduled for immediate first execution and returned to the caller.

a task reference, as per the rules stated above.
Parameters:
  task - the task whose periodicity is to be set
Parameters:
  period - the new period




shutdown
public synchronized void shutdown()(Code)
Shuts down this timer after the current task (if any) completes.

After this call, the timer has permanently entered the shutdown state; attempting to schedule any new task or directly restart this timer will result in an IllegalStateException.




shutdownImmediately
public synchronized void shutdownImmediately()(Code)
Shuts down this timer immediately, interrupting the wait state associated with the current head of the task queue or the wait state internal to the currently executing task, if any such state is currently in effect. After this call, the timer has permanently entered the shutdown state; attempting to schedule any new task or directly restart this timer will result in an IllegalStateException.

Note: If the integrity of work performed by a scheduled task may be adversely affected by an unplanned interruption, it is the responsibility of the task's implementation to deal correctly with the possibility that this method is called while such work is in progress, for instance by catching the InterruptedException, completing the work, and then rethrowing the exception.




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.