Source Code Cross Referenced for ScheduledExecutorService.java in  » Apache-Harmony-Java-SE » java-package » java » util » concurrent » 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 » Apache Harmony Java SE » java package » java.util.concurrent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Written by Doug Lea with assistance from members of JCP JSR-166
003:         * Expert Group and released to the public domain, as explained at
004:         * http://creativecommons.org/licenses/publicdomain
005:         */
006:
007:        package java.util.concurrent;
008:
009:        import java.util.concurrent.atomic.*;
010:        import java.util.*;
011:
012:        /**
013:         * An {@link ExecutorService} that can schedule commands to run after a given
014:         * delay, or to execute periodically. 
015:         *
016:         * <p> The <tt>schedule</tt> methods create tasks with various delays
017:         * and return a task object that can be used to cancel or check
018:         * execution. The <tt>scheduleAtFixedRate</tt> and
019:         * <tt>scheduleWithFixedDelay</tt> methods create and execute tasks
020:         * that run periodically until cancelled.  
021:         *
022:         * <p> Commands submitted using the {@link Executor#execute} and
023:         * {@link ExecutorService} <tt>submit</tt> methods are scheduled with
024:         * a requested delay of zero. Zero and negative delays (but not
025:         * periods) are also allowed in <tt>schedule</tt> methods, and are
026:         * treated as requests for immediate execution.
027:         *
028:         * <p>All <tt>schedule</tt> methods accept <em>relative</em> delays and
029:         * periods as arguments, not absolute times or dates. It is a simple
030:         * matter to transform an absolute time represented as a {@link
031:         * java.util.Date} to the required form. For example, to schedule at
032:         * a certain future <tt>date</tt>, you can use: <tt>schedule(task,
033:         * date.getTime() - System.currentTimeMillis(),
034:         * TimeUnit.MILLISECONDS)</tt>. Beware however that expiration of a
035:         * relative delay need not coincide with the current <tt>Date</tt> at
036:         * which the task is enabled due to network time synchronization
037:         * protocols, clock drift, or other factors. 
038:         *
039:         * The {@link Executors} class provides convenient factory methods for
040:         * the ScheduledExecutorService implementations provided in this package.
041:         *
042:         * <h3>Usage Example</h3>
043:         * 
044:         * Here is a class with a method that sets up a ScheduledExecutorService
045:         * to beep every ten seconds for an hour:
046:         *
047:         * <pre>
048:         * import static java.util.concurrent.TimeUnit;
049:         * class BeeperControl {
050:         *    private final ScheduledExecutorService scheduler = 
051:         *       Executors.newScheduledThreadPool(1);
052:         *
053:         *    public void beepForAnHour() {
054:         *        final Runnable beeper = new Runnable() {
055:         *                public void run() { System.out.println("beep"); }
056:         *            };
057:         *        final ScheduledFuture&lt;?&gt; beeperHandle = 
058:         *            scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
059:         *        scheduler.schedule(new Runnable() {
060:         *                public void run() { beeperHandle.cancel(true); }
061:         *            }, 60 * 60, SECONDS);
062:         *    }
063:         * }
064:         * </pre>
065:         *
066:         * @since 1.5
067:         * @author Doug Lea
068:         */
069:        public interface ScheduledExecutorService extends ExecutorService {
070:
071:            /**
072:             * Creates and executes a one-shot action that becomes enabled
073:             * after the given delay.
074:             * @param command the task to execute.
075:             * @param delay the time from now to delay execution.
076:             * @param unit the time unit of the delay parameter.
077:             * @return a Future representing pending completion of the task,
078:             * and whose <tt>get()</tt> method will return <tt>null</tt>
079:             * upon completion.
080:             * @throws RejectedExecutionException if task cannot be scheduled
081:             * for execution.
082:             * @throws NullPointerException if command is null
083:             */
084:            public ScheduledFuture<?> schedule(Runnable command, long delay,
085:                    TimeUnit unit);
086:
087:            /**
088:             * Creates and executes a ScheduledFuture that becomes enabled after the
089:             * given delay.
090:             * @param callable the function to execute.
091:             * @param delay the time from now to delay execution.
092:             * @param unit the time unit of the delay parameter.
093:             * @return a ScheduledFuture that can be used to extract result or cancel.
094:             * @throws RejectedExecutionException if task cannot be scheduled
095:             * for execution.
096:             * @throws NullPointerException if callable is null
097:             */
098:            public <V> ScheduledFuture<V> schedule(Callable<V> callable,
099:                    long delay, TimeUnit unit);
100:
101:            /**
102:             * Creates and executes a periodic action that becomes enabled first
103:             * after the given initial delay, and subsequently with the given
104:             * period; that is executions will commence after
105:             * <tt>initialDelay</tt> then <tt>initialDelay+period</tt>, then
106:             * <tt>initialDelay + 2 * period</tt>, and so on.  
107:             * If any execution of the task
108:             * encounters an exception, subsequent executions are suppressed.
109:             * Otherwise, the task will only terminate via cancellation or
110:             * termination of the executor.
111:             * @param command the task to execute.
112:             * @param initialDelay the time to delay first execution.
113:             * @param period the period between successive executions.
114:             * @param unit the time unit of the initialDelay and period parameters
115:             * @return a Future representing pending completion of the task,
116:             * and whose <tt>get()</tt> method will throw an exception upon
117:             * cancellation.
118:             * @throws RejectedExecutionException if task cannot be scheduled
119:             * for execution.
120:             * @throws NullPointerException if command is null
121:             * @throws IllegalArgumentException if period less than or equal to zero.
122:             */
123:            public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
124:                    long initialDelay, long period, TimeUnit unit);
125:
126:            /**
127:             * Creates and executes a periodic action that becomes enabled first
128:             * after the given initial delay, and subsequently with the
129:             * given delay between the termination of one execution and the
130:             * commencement of the next. If any execution of the task
131:             * encounters an exception, subsequent executions are suppressed.
132:             * Otherwise, the task will only terminate via cancellation or
133:             * termination of the executor.
134:             * @param command the task to execute.
135:             * @param initialDelay the time to delay first execution.
136:             * @param delay the delay between the termination of one
137:             * execution and the commencement of the next.
138:             * @param unit the time unit of the initialDelay and delay parameters
139:             * @return a Future representing pending completion of the task,
140:             * and whose <tt>get()</tt> method will throw an exception upon
141:             * cancellation.
142:             * @throws RejectedExecutionException if task cannot be scheduled
143:             * for execution.
144:             * @throws NullPointerException if command is null
145:             * @throws IllegalArgumentException if delay less than or equal to zero.
146:             */
147:            public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
148:                    long initialDelay, long delay, TimeUnit unit);
149:
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.