Source Code Cross Referenced for GWThreadPool.java in  » Portal » Open-Portal » com » sun » portal » 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 » Portal » Open Portal » com.sun.portal.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: GWThreadPool.java,v 1.9 2005/12/09 10:38:17 ss150821 Exp $
003:         * $Source: /m/portal/ps/srap/src/com/sun/portal/util/GWThreadPool.java,v $
004:         * $Log: GWThreadPool.java,v $
005:         * Revision 1.9  2005/12/09 10:38:17  ss150821
006:         * 4925306
007:         *
008:         * Revision 1.8  2005/11/30 05:57:43  ss150821
009:         * 4925306
010:         *
011:         * Revision 1.7  2005/03/18 06:41:46  np145014
012:         * CR 6223492
013:         *
014:         * Revision 1.6  2005/03/01 10:36:06  np145014
015:         * CR 6224556
016:         *
017:         * Revision 1.5  2005/02/23 11:39:13  ss150821
018:         * RFE 6223490 - SRA Should use JDK based logging
019:         *
020:         * Revision 1.4  2005/02/21 08:03:16  ss150821
021:         * 6223490 - JDK Logging move for SRA
022:         *
023:         * Revision 1.3  2005/02/17 08:27:38  ss150821
024:         * RFE 6223490 - Add JDK Logging Support to SRA
025:         *
026:         * Revision 1.2  2002/06/21 13:04:15  bv131302
027:         * LDAP Attribute name changes
028:         *
029:         * Revision 1.1  2002/06/14 09:04:23  rt130506
030:         * SRAP rebranding
031:         *
032:         * Revision 1.3  2002/06/11 16:02:12  bv131302
033:         * new branded
034:         *
035:         * Revision 1.2  2002/05/13 06:22:26  mm132998
036:         * Perf related modifications
037:         *
038:         */
039:        /*
040:         * @(#)GWThreadPool.java	1.2 00/11/15
041:         *
042:         * Copyright (c) 11/15/00 Sun Microsystems, Inc. All Rights Reserved.
043:         */
044:
045:        package com.sun.portal.util;
046:
047:        import com.sun.portal.rproxy.configservlet.client.GatewayProfile;
048:
049:        public class GWThreadPool {
050:
051:            private static int threadPoolSize;
052:
053:            private static _ThreadPool threadPool;
054:            protected final static ThreadGroup threadGroup = new ThreadGroup(
055:                    "GW ThreadPool Group");
056:
057:            public static void init() {
058:                threadPoolSize = GatewayProfile
059:                        .getInt("MaxThreadPoolSize", 500);
060:
061:                threadPool = new _ThreadPool(threadPoolSize);
062:            }
063:
064:            public static void run(Runnable task) throws InterruptedException {
065:                _ThreadPool.poolMon.poolThreadStart();
066:                threadPool.run(task);
067:            }
068:
069:            public static int getSize() {
070:                return threadPoolSize;
071:            }
072:
073:            public static int getRequestsInQue() {
074:                return threadPool.getSize();
075:            }
076:
077:            public static int getActiveThreads() {
078:                //return threadGroup.activeCount();
079:                //return threadGroup.enumerate(new Thread[threadGroup.activeCount()]);
080:                return threadPool.poolMon.getActiveThreads();
081:            }
082:
083:        }
084:
085:        class Que implements  java.io.Serializable {
086:
087:            private java.util.List list = new java.util.ArrayList();
088:
089:            synchronized public void put(Runnable obj) {
090:                TaskWrapper task = (TaskWrapper) TaskWrapper.wrap(obj);
091:                task.queued();
092:                list.add(task);
093:                notify();
094:            }
095:
096:            synchronized public Runnable get() {
097:                while (list.isEmpty()) {
098:                    try {
099:                        wait();
100:                    } catch (InterruptedException ex) {
101:                    }
102:                }
103:                TaskWrapper taskWrapper = (TaskWrapper) list.remove(0);
104:                taskWrapper.deQueued();
105:
106:                return taskWrapper;
107:            }
108:
109:            synchronized public int size() {
110:                return list.size();
111:            }
112:        }
113:
114:        class _ThreadPool {
115:            public static PoolMonitor poolMon = new PoolMonitor();
116:            private Que tasks = new Que();
117:
118:            public _ThreadPool(int threadCount) {
119:                for (int i = 0; i < threadCount; i++) {
120:                    ThreadPoolThread thread = new ThreadPoolThread(this , i);
121:                    thread.start();
122:                }
123:            }
124:
125:            public void run(Runnable task) {
126:                tasks.put(task);
127:            }
128:
129:            public Runnable getNextRunnable() {
130:                return (Runnable) tasks.get();
131:            }
132:
133:            public int getSize() {
134:                return tasks.size();
135:            }
136:        }
137:
138:        class ThreadPoolThread extends Thread {
139:
140:            private _ThreadPool pool;
141:
142:            public ThreadPoolThread(_ThreadPool pool, int id) {
143:                super (GWThreadPool.threadGroup, "ID_" + id);
144:                this .pool = pool;
145:            }
146:
147:            public void run() {
148:                ThreadMonitorContext.startThread();
149:
150:                try {
151:                    while (true) {
152:                        ThreadMonitorContext.waitingInQueue();
153:                        Runnable task = pool.getNextRunnable();
154:                        if (task != null) {
155:                            try {
156:                                ThreadMonitorContext.newTask(task);
157:                                task.run();
158:                                ThreadMonitorContext.taskEnds();
159:                            } catch (Throwable ex) {
160:                                ThreadMonitorContext.taskEnds();
161:                                if (GWDebug.debug.messageEnabled()) {
162:                                    GWDebug.debug.message(
163:                                            "Threadpool caught Exception : ",
164:                                            ex);
165:                                }
166:                            }
167:                        }
168:                    }
169:                } finally {
170:                    pool.poolMon.poolThreadEnd();
171:                    ThreadMonitorContext.endThread();
172:                }
173:            }
174:        }
175:
176:        class PoolMonitor {
177:            boolean pool_started = false;
178:
179:            int activeThreads = 0;
180:
181:            synchronized void poolThreadStart() {
182:                activeThreads++;
183:                pool_started = true;
184:            }
185:
186:            synchronized void poolThreadEnd() {
187:                activeThreads--;
188:            }
189:
190:            synchronized int getActiveThreads() {
191:                return activeThreads;
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.