Source Code Cross Referenced for ThreadPool.java in  » Sevlet-Container » jetty-extras » org » mortbay » thread » 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 » Sevlet Container » jetty extras » org.mortbay.thread.concurrent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // ========================================================================
002:        // Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
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:        // http://www.apache.org/licenses/LICENSE-2.0
008:        // Unless required by applicable law or agreed to in writing, software
009:        // distributed under the License is distributed on an "AS IS" BASIS,
010:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011:        // See the License for the specific language governing permissions and
012:        // limitations under the License.
013:        // ========================================================================
014:
015:        package org.mortbay.thread.concurrent;
016:
017:        import java.util.concurrent.ArrayBlockingQueue;
018:        import java.util.concurrent.BlockingQueue;
019:        import java.util.concurrent.LinkedBlockingQueue;
020:        import java.util.concurrent.RejectedExecutionException;
021:        import java.util.concurrent.RejectedExecutionHandler;
022:        import java.util.concurrent.SynchronousQueue;
023:        import java.util.concurrent.ThreadFactory;
024:        import java.util.concurrent.ThreadPoolExecutor;
025:        import java.util.concurrent.TimeUnit;
026:
027:        import org.mortbay.component.LifeCycle;
028:        import org.mortbay.log.Log;
029:
030:        /* ------------------------------------------------------------ */
031:        /** Jetty ThreadPool using java 5 ThreadPoolExecutor
032:         * This class wraps a {@link ThreadPoolExecutor} with the {@link org.mortbay.thread.ThreadPool} and 
033:         * {@link LifeCycle} interfaces so that it may be used by the Jetty {@link org.mortbay.jetty.Server}
034:         * 
035:         * @author gregw
036:         *
037:         */
038:        public class ThreadPool extends ThreadPoolExecutor implements 
039:                org.mortbay.thread.ThreadPool, LifeCycle {
040:
041:            /* ------------------------------------------------------------ */
042:            /** Default constructor.
043:             * Core size is 32, max pool size is 256, pool thread timeout after 60 seconds and
044:             * an unbounded {@link LinkedBlockingQueue} is used for the job queue;
045:             */
046:            public ThreadPool() {
047:                super (32, 256, 60, TimeUnit.SECONDS,
048:                        new LinkedBlockingQueue<Runnable>());
049:            }
050:
051:            /* ------------------------------------------------------------ */
052:            /** Default constructor.
053:             * Core size is 32, max pool size is 256, pool thread timeout after 60 seconds
054:             * @param queueSize if -1, an unbounded {@link LinkedBlockingQueue} is used, if 0 then a
055:             * {@link SynchronousQueue} is used, other a {@link ArrayBlockingQueue} of the given size is used.
056:             */
057:            public ThreadPool(int queueSize) {
058:                super (
059:                        32,
060:                        256,
061:                        60,
062:                        TimeUnit.SECONDS,
063:                        queueSize < 0 ? new LinkedBlockingQueue<Runnable>()
064:                                : (queueSize == 0 ? new SynchronousQueue<Runnable>()
065:                                        : new ArrayBlockingQueue<Runnable>(
066:                                                queueSize)));
067:            }
068:
069:            /* ------------------------------------------------------------ */
070:            /** Size constructor.
071:             * an unbounded {@link LinkedBlockingQueue} is used for the jobs queue;
072:             */
073:            public ThreadPool(int corePoolSize, int maximumPoolSize,
074:                    long keepAliveTime, TimeUnit unit) {
075:                super (corePoolSize, maximumPoolSize, keepAliveTime, unit,
076:                        new LinkedBlockingQueue<Runnable>());
077:            }
078:
079:            /* ------------------------------------------------------------ */
080:            public ThreadPool(int corePoolSize, int maximumPoolSize,
081:                    long keepAliveTime, TimeUnit unit,
082:                    BlockingQueue<Runnable> workQueue) {
083:                super (corePoolSize, maximumPoolSize, keepAliveTime, unit,
084:                        workQueue);
085:            }
086:
087:            /* ------------------------------------------------------------ */
088:            public ThreadPool(int corePoolSize, int maximumPoolSize,
089:                    long keepAliveTime, TimeUnit unit,
090:                    BlockingQueue<Runnable> workQueue,
091:                    RejectedExecutionHandler handler) {
092:                super (corePoolSize, maximumPoolSize, keepAliveTime, unit,
093:                        workQueue, handler);
094:            }
095:
096:            /* ------------------------------------------------------------ */
097:            public ThreadPool(int corePoolSize, int maximumPoolSize,
098:                    long keepAliveTime, TimeUnit unit,
099:                    BlockingQueue<Runnable> workQueue,
100:                    ThreadFactory threadFactory,
101:                    RejectedExecutionHandler handler) {
102:                super (corePoolSize, maximumPoolSize, keepAliveTime, unit,
103:                        workQueue, threadFactory, handler);
104:            }
105:
106:            /* ------------------------------------------------------------ */
107:            public ThreadPool(int corePoolSize, int maximumPoolSize,
108:                    long keepAliveTime, TimeUnit unit,
109:                    BlockingQueue<Runnable> workQueue,
110:                    ThreadFactory threadFactory) {
111:                super (corePoolSize, maximumPoolSize, keepAliveTime, unit,
112:                        workQueue, threadFactory);
113:            }
114:
115:            /* ------------------------------------------------------------ */
116:            public boolean dispatch(Runnable job) {
117:                try {
118:                    execute(job);
119:                    return true;
120:                } catch (RejectedExecutionException e) {
121:                    Log.warn(e);
122:                    return false;
123:                }
124:            }
125:
126:            /* ------------------------------------------------------------ */
127:            public int getIdleThreads() {
128:                return getPoolSize() - getActiveCount();
129:            }
130:
131:            /* ------------------------------------------------------------ */
132:            public int getThreads() {
133:                return getPoolSize();
134:            }
135:
136:            /* ------------------------------------------------------------ */
137:            public boolean isLowOnThreads() {
138:                return getActiveCount() >= getMaximumPoolSize();
139:            }
140:
141:            /* ------------------------------------------------------------ */
142:            public void join() throws InterruptedException {
143:                this .awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
144:            }
145:
146:            /* ------------------------------------------------------------ */
147:            public boolean isFailed() {
148:                return false;
149:            }
150:
151:            /* ------------------------------------------------------------ */
152:            public boolean isRunning() {
153:                return !isTerminated() && !isTerminating();
154:            }
155:
156:            /* ------------------------------------------------------------ */
157:            public boolean isStarted() {
158:                return !isTerminated() && !isTerminating();
159:            }
160:
161:            /* ------------------------------------------------------------ */
162:            public boolean isStarting() {
163:                return false;
164:            }
165:
166:            /* ------------------------------------------------------------ */
167:            public boolean isStopped() {
168:                return isTerminated();
169:            }
170:
171:            /* ------------------------------------------------------------ */
172:            public boolean isStopping() {
173:                return isTerminating();
174:            }
175:
176:            /* ------------------------------------------------------------ */
177:            public void start() throws Exception {
178:                if (isTerminated() || isTerminating() || isShutdown())
179:                    throw new IllegalStateException("Cannot restart");
180:            }
181:
182:            /* ------------------------------------------------------------ */
183:            public void stop() throws Exception {
184:                super .shutdown();
185:                if (!super .awaitTermination(60, TimeUnit.SECONDS))
186:                    super.shutdownNow();
187:            }
188:
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.