Source Code Cross Referenced for KSBThreadPoolImpl.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » messaging » threadpool » 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 » ERP CRM Financial » Kuali Financial System » edu.iu.uis.eden.messaging.threadpool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 The Kuali Foundation
003:         *
004:         * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
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:        package edu.iu.uis.eden.messaging.threadpool;
017:
018:        import org.apache.log4j.Logger;
019:        import org.kuali.rice.config.Config;
020:        import org.kuali.rice.core.Core;
021:
022:        import edu.emory.mathcs.backport.java.util.concurrent.Executors;
023:        import edu.emory.mathcs.backport.java.util.concurrent.PriorityBlockingQueue;
024:        import edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory;
025:        import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
026:        import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
027:
028:        /**
029:         * A Thread Pool implementation for the KSB which implements a thread pool backed by a configuration store.
030:         * 
031:         * @author Kuali Rice Team (kuali-rice@googlegroups.com)
032:         */
033:        public class KSBThreadPoolImpl extends ThreadPoolExecutor implements 
034:                KSBThreadPool {
035:
036:            private static final Logger LOG = Logger
037:                    .getLogger(KSBThreadPoolImpl.class);
038:
039:            public static final int DEFAULT_POOL_SIZE = 5;
040:
041:            private boolean started;
042:            private boolean poolSizeSet;
043:
044:            public KSBThreadPoolImpl() {
045:                super (
046:                        DEFAULT_POOL_SIZE,
047:                        DEFAULT_POOL_SIZE,
048:                        60,
049:                        TimeUnit.SECONDS,
050:                        new PriorityBlockingQueue(
051:                                1,
052:                                new PriorityBlockingQueuePersistedMessageComparator()),
053:                        new KSBThreadFactory(),
054:                        new ThreadPoolExecutor.AbortPolicy());
055:            }
056:
057:            public void setCorePoolSize(int corePoolSize) {
058:                LOG.info("Setting core pool size to " + corePoolSize
059:                        + " threads.");
060:                super .setCorePoolSize(corePoolSize);
061:                this .poolSizeSet = true;
062:            }
063:
064:            public long getKeepAliveTime() {
065:                return super .getKeepAliveTime(TimeUnit.MILLISECONDS);
066:            }
067:
068:            public boolean isStarted() {
069:                return this .started;
070:            }
071:
072:            public void start() throws Exception {
073:
074:            }
075:
076:            public void stop() throws Exception {
077:                LOG.info("Shutting down KSB threadpool.");
078:                if (isStarted()) {
079:                    this .shutdownNow();
080:                    this .started = false;
081:                }
082:            }
083:
084:            /**
085:             * Loads the thread pool settings from the DAO.
086:             */
087:            protected void loadSettings() {
088:                Core.getCurrentContextConfig().getProperty(
089:                        Config.THREAD_POOL_SIZE);
090:
091:                if (!this .poolSizeSet) {
092:                    int poolSize;
093:                    try {
094:                        poolSize = new Integer(Core.getCurrentContextConfig()
095:                                .getProperty(Config.THREAD_POOL_SIZE));
096:                    } catch (NumberFormatException nfe) {
097:                        poolSize = -1;
098:                    }
099:                    if (poolSize == -1) {
100:                        poolSize = DEFAULT_POOL_SIZE;
101:                    }
102:                    setCorePoolSize(poolSize);
103:                }
104:
105:            }
106:
107:            public Object getInstance() {
108:                return this ;
109:            }
110:
111:            /**
112:             * A simple ThreadFactory which names the thread as follows:<br>
113:             * <br>
114:             * 
115:             * <i>messageEntity</i>/KSB-pool-<i>m</i>-thread-<i>n</i><br>
116:             * <br>
117:             * 
118:             * Where <i>messageEntity</i> is the message entity of the application running the thread pool, <i>m</i> is the
119:             * sequence number of the factory and <i>n</i> is the sequence number of the thread within the factory.
120:             * 
121:             * @author Kuali Rice Team (kuali-rice@googlegroups.com)
122:             */
123:            private static class KSBThreadFactory implements  ThreadFactory {
124:
125:                private static int factorySequence = 0;
126:
127:                private static int threadSequence = 0;
128:
129:                private ThreadFactory defaultThreadFactory = Executors
130:                        .defaultThreadFactory();
131:
132:                public KSBThreadFactory() {
133:                    factorySequence++;
134:                }
135:
136:                public Thread newThread(Runnable runnable) {
137:                    threadSequence++;
138:                    Thread thread = this .defaultThreadFactory
139:                            .newThread(runnable);
140:                    thread.setName(Core.getCurrentContextConfig()
141:                            .getMessageEntity()
142:                            + "/KSB-pool-"
143:                            + factorySequence
144:                            + "-thread-"
145:                            + threadSequence);
146:                    return thread;
147:                }
148:
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.