Source Code Cross Referenced for ScheduledTimerTask.java in  » J2EE » spring-framework-2.5 » org » springframework » scheduling » timer » 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 » J2EE » spring framework 2.5 » org.springframework.scheduling.timer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.scheduling.timer;
018:
019:        import java.util.TimerTask;
020:
021:        /**
022:         * JavaBean that describes a scheduled {@link TimerTask}, consisting of the
023:         * {@link TimerTask} itself or a {@link Runnable} to create a {@link TimerTask}
024:         * for and a delay plus period. The period needs to be specified; there is
025:         * no point in a default for it.
026:         *
027:         * <p>The JDK's {@link java.util.Timer} facility does not offer sophisticated
028:         * scheduling options such as cron expressions. Consider using Quartz for
029:         * such advanced needs.
030:         *
031:         * <p>Note that the {@link java.util.Timer} mechanism uses a {@link TimerTask}
032:         * instance that is shared between repeated executions, in contrast to Quartz
033:         * which creates a new Job instance for each execution.
034:         *
035:         * @author Juergen Hoeller
036:         * @since 19.02.2004
037:         * @see java.util.TimerTask
038:         * @see java.util.Timer#schedule(TimerTask, long, long)
039:         * @see java.util.Timer#scheduleAtFixedRate(TimerTask, long, long)
040:         */
041:        public class ScheduledTimerTask {
042:
043:            private TimerTask timerTask;
044:
045:            private long delay = 0;
046:
047:            private long period = -1;
048:
049:            private boolean fixedRate = false;
050:
051:            /**
052:             * Create a new ScheduledTimerTask,
053:             * to be populated via bean properties.
054:             * @see #setTimerTask
055:             * @see #setDelay
056:             * @see #setPeriod
057:             * @see #setFixedRate
058:             */
059:            public ScheduledTimerTask() {
060:            }
061:
062:            /**
063:             * Create a new ScheduledTimerTask, with default
064:             * one-time execution without delay.
065:             * @param timerTask the TimerTask to schedule
066:             */
067:            public ScheduledTimerTask(TimerTask timerTask) {
068:                this .timerTask = timerTask;
069:            }
070:
071:            /**
072:             * Create a new ScheduledTimerTask, with default
073:             * one-time execution with the given delay.
074:             * @param timerTask the TimerTask to schedule
075:             * @param delay the delay before starting the task for the first time (ms)
076:             */
077:            public ScheduledTimerTask(TimerTask timerTask, long delay) {
078:                this .timerTask = timerTask;
079:                this .delay = delay;
080:            }
081:
082:            /**
083:             * Create a new ScheduledTimerTask.
084:             * @param timerTask the TimerTask to schedule
085:             * @param delay the delay before starting the task for the first time (ms)
086:             * @param period the period between repeated task executions (ms)
087:             * @param fixedRate whether to schedule as fixed-rate execution
088:             */
089:            public ScheduledTimerTask(TimerTask timerTask, long delay,
090:                    long period, boolean fixedRate) {
091:                this .timerTask = timerTask;
092:                this .delay = delay;
093:                this .period = period;
094:                this .fixedRate = fixedRate;
095:            }
096:
097:            /**
098:             * Create a new ScheduledTimerTask, with default
099:             * one-time execution without delay.
100:             * @param timerTask the Runnable to schedule as TimerTask
101:             */
102:            public ScheduledTimerTask(Runnable timerTask) {
103:                setRunnable(timerTask);
104:            }
105:
106:            /**
107:             * Create a new ScheduledTimerTask, with default
108:             * one-time execution with the given delay.
109:             * @param timerTask the Runnable to schedule as TimerTask
110:             * @param delay the delay before starting the task for the first time (ms)
111:             */
112:            public ScheduledTimerTask(Runnable timerTask, long delay) {
113:                setRunnable(timerTask);
114:                this .delay = delay;
115:            }
116:
117:            /**
118:             * Create a new ScheduledTimerTask.
119:             * @param timerTask the Runnable to schedule as TimerTask
120:             * @param delay the delay before starting the task for the first time (ms)
121:             * @param period the period between repeated task executions (ms)
122:             * @param fixedRate whether to schedule as fixed-rate execution
123:             */
124:            public ScheduledTimerTask(Runnable timerTask, long delay,
125:                    long period, boolean fixedRate) {
126:                setRunnable(timerTask);
127:                this .delay = delay;
128:                this .period = period;
129:                this .fixedRate = fixedRate;
130:            }
131:
132:            /**
133:             * Set the Runnable to schedule as TimerTask.
134:             * @see DelegatingTimerTask
135:             */
136:            public void setRunnable(Runnable timerTask) {
137:                this .timerTask = new DelegatingTimerTask(timerTask);
138:            }
139:
140:            /**
141:             * Set the TimerTask to schedule.
142:             */
143:            public void setTimerTask(TimerTask timerTask) {
144:                this .timerTask = timerTask;
145:            }
146:
147:            /**
148:             * Return the TimerTask to schedule.
149:             */
150:            public TimerTask getTimerTask() {
151:                return this .timerTask;
152:            }
153:
154:            /**
155:             * Set the delay before starting the task for the first time,
156:             * in milliseconds. Default is 0, immediately starting the
157:             * task after successful scheduling.
158:             */
159:            public void setDelay(long delay) {
160:                this .delay = delay;
161:            }
162:
163:            /**
164:             * Return the delay before starting the job for the first time.
165:             */
166:            public long getDelay() {
167:                return this .delay;
168:            }
169:
170:            /**
171:             * Set the period between repeated task executions, in milliseconds.
172:             * <p>Default is -1, leading to one-time execution. In case of a positive
173:             * value, the task will be executed repeatedly, with the given interval
174:             * inbetween executions.
175:             * <p>Note that the semantics of the period value vary between fixed-rate
176:             * and fixed-delay execution.
177:             * <p><b>Note:</b> A period of 0 (for example as fixed delay) is <i>not</i>
178:             * supported, simply because <code>java.util.Timer</code> itself does not
179:             * support it. Hence a value of 0 will be treated as one-time execution;
180:             * however, that value should never be specified explicitly in the first place!
181:             * @see #setFixedRate
182:             * @see #isOneTimeTask()
183:             * @see java.util.Timer#schedule(TimerTask, long, long)
184:             */
185:            public void setPeriod(long period) {
186:                this .period = period;
187:            }
188:
189:            /**
190:             * Return the period between repeated task executions.
191:             */
192:            public long getPeriod() {
193:                return this .period;
194:            }
195:
196:            /**
197:             * Is this task only ever going to execute once?
198:             * @return <code>true</code> if this task is only ever going to execute once
199:             * @see #getPeriod()
200:             */
201:            public boolean isOneTimeTask() {
202:                return (this .period <= 0);
203:            }
204:
205:            /**
206:             * Set whether to schedule as fixed-rate execution, rather than
207:             * fixed-delay execution. Default is "false", that is, fixed delay.
208:             * <p>See Timer javadoc for details on those execution modes.
209:             * @see java.util.Timer#schedule(TimerTask, long, long)
210:             * @see java.util.Timer#scheduleAtFixedRate(TimerTask, long, long)
211:             */
212:            public void setFixedRate(boolean fixedRate) {
213:                this .fixedRate = fixedRate;
214:            }
215:
216:            /**
217:             * Return whether to schedule as fixed-rate execution.
218:             */
219:            public boolean isFixedRate() {
220:                return this.fixedRate;
221:            }
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.