Source Code Cross Referenced for TimerTask.java in  » 6.0-JDK-Modules » j2me » java » util » 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 » 6.0 JDK Modules » j2me » java.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package java.util;
028:
029:        /**
030:         * A task that can be scheduled for one-time or repeated execution by a
031:         * <code>Timer</code>.
032:         *
033:         * @version 1.5, 12/04/99
034:         * @see	    Timer
035:         * @since   1.3
036:         */
037:
038:        public abstract class TimerTask implements  Runnable {
039:            /**
040:             * This object is used to control access to the TimerTask internals.
041:             */
042:            final Object lock = new Object();
043:
044:            /**
045:             * The state of this task, chosen from the constants below.
046:             */
047:            int state = VIRGIN;
048:
049:            /**
050:             * This task has not yet been scheduled.
051:             */
052:            static final int VIRGIN = 0;
053:
054:            /**
055:             * This task is scheduled for execution.  If it is a non-repeating task,
056:             * it has not yet been executed.
057:             */
058:            static final int SCHEDULED = 1;
059:
060:            /**
061:             * This non-repeating task has already executed (or is currently
062:             * executing) and has not been cancelled.
063:             */
064:            static final int EXECUTED = 2;
065:
066:            /**
067:             * This task has been cancelled (with a call to TimerTask.cancel).
068:             */
069:            static final int CANCELLED = 3;
070:
071:            /**
072:             * Next execution time for this task in the format returned by
073:             * System.currentTimeMillis, assuming this task is schedule for execution.
074:             * For repeating tasks, this field is updated prior to each task execution.
075:             */
076:            long nextExecutionTime;
077:
078:            /**
079:             * Period in milliseconds for repeating tasks.  A positive value indicates
080:             * fixed-rate execution.  A negative value indicates fixed-delay execution.
081:             * A value of 0 indicates a non-repeating task.
082:             */
083:            long period = 0;
084:
085:            /**
086:             * Creates a new timer task.
087:             */
088:            protected TimerTask() {
089:            }
090:
091:            /**
092:             * The action to be performed by this timer task.
093:             */
094:            public abstract void run();
095:
096:            /**
097:             * Cancels this timer task.  If the task has been scheduled for one-time
098:             * execution and has not yet run, or has not yet been scheduled, it will
099:             * never run.  If the task has been scheduled for repeated execution, it
100:             * will never run again.  (If the task is running when this call occurs,
101:             * the task will run to completion, but will never run again.)
102:             *
103:             * <p>Note that calling this method from within the <tt>run</tt> method of
104:             * a repeating timer task absolutely guarantees that the timer task will
105:             * not run again.
106:             *
107:             * <p>This method may be called repeatedly; the second and subsequent 
108:             * calls have no effect.
109:             *
110:             * @return true if this task is scheduled for one-time execution and has
111:             *         not yet run, or this task is scheduled for repeated execution.
112:             *         Returns false if the task was scheduled for one-time execution
113:             *         and has already run, or if the task was never scheduled, or if
114:             *         the task was already cancelled.  (Loosely speaking, this method
115:             *         returns <tt>true</tt> if it prevents one or more scheduled
116:             *         executions from taking place.)
117:             */
118:            public boolean cancel() {
119:                synchronized (lock) {
120:                    boolean result = (state == SCHEDULED);
121:                    state = CANCELLED;
122:                    return result;
123:                }
124:            }
125:
126:            /**
127:             * Returns the <i>scheduled</i> execution time of the most recent
128:             * <i>actual</i> execution of this task.  (If this method is invoked
129:             * while task execution is in progress, the return value is the scheduled
130:             * execution time of the ongoing task execution.)
131:             *
132:             * <p>This method is typically invoked from within a task's run method, to
133:             * determine whether the current execution of the task is sufficiently
134:             * timely to warrant performing the scheduled activity:
135:             * <pre>
136:             *   public void run() {
137:             *       if (System.currentTimeMillis() - scheduledExecutionTime() >=
138:             *           MAX_TARDINESS)
139:             *               return;  // Too late; skip this execution.
140:             *       // Perform the task
141:             *   }
142:             * </pre>
143:             * This method is typically <i>not</i> used in conjunction with
144:             * <i>fixed-delay execution</i> repeating tasks, as their scheduled
145:             * execution times are allowed to drift over time, and so are not terribly
146:             * significant.
147:             *
148:             * @return the time at which the most recent execution of this task was
149:             *         scheduled to occur, in the format returned by Date.getTime().
150:             *         The return value is undefined if the task has yet to commence
151:             *         its first execution.
152:             * @see Date#getTime()
153:             */
154:            public long scheduledExecutionTime() {
155:                synchronized (lock) {
156:                    return (period < 0 ? nextExecutionTime + period
157:                            : nextExecutionTime - period);
158:                }
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.