Source Code Cross Referenced for AnyThreadPool.java in  » Web-Framework » anvil » anvil » core » runtime » 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 » Web Framework » anvil » anvil.core.runtime 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: AnyThreadPool.java,v 1.7 2002/09/16 08:05:03 jkl Exp $
003:         *
004:         * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
005:         *
006:         * Use is subject to license terms, as defined in
007:         * Anvil Sofware License, Version 1.1. See LICENSE 
008:         * file, or http://njet.org/license-1.1.txt
009:         */
010:        package anvil.core.runtime;
011:
012:        import anvil.java.lang.ThreadPool;
013:        import anvil.core.Any;
014:        import anvil.core.AnyAbstractClass;
015:        import anvil.script.Context;
016:        import anvil.script.Function;
017:
018:        /// @class ThreadPool
019:        /// ThreadPool is pool of re-usable threads. 
020:        /// Re-use of threads is beneficial as the relative heavy-weight 
021:        /// creation of thread can be avoided.
022:
023:        /**
024:         * class AnyThreadPool
025:         *
026:         * @author: Jani Lehtimäki
027:         */
028:        public class AnyThreadPool extends AnyAbstractClass {
029:
030:            public static final anvil.core.RuntimePermission CAN_USE = new anvil.core.RuntimePermission(
031:                    "anvil.runtime.ThreadPool", false);
032:
033:            /// @constructor ThreadPool
034:            /// Creates new thread pool.
035:            /// @synopsis ThreadPool()
036:            /// @synopsis ThreadPool(string name)
037:            /// @synopsis ThreadPool(string name, int maxthreads)
038:            /// @synopsis ThreadPool(string name, int maxthreads, int maxtasks)
039:            public static final Object[] newInstance = new Object[] { null,
040:                    "*name", null, "*threads", new Integer(0), "*tasks",
041:                    new Integer(0) };
042:
043:            public static final Any newInstance(Context context, String name,
044:                    int threads, int tasks) {
045:                context.checkAccess(AnyThreadPool.CAN_USE);
046:                if (name == null) {
047:                    name = "Pool";
048:                }
049:                ThreadPool pool = new ThreadPool(name);
050:                if (threads > 0) {
051:                    pool.setMaxThreads(threads);
052:                }
053:                if (tasks > 0) {
054:                    pool.setMaxTasks(tasks);
055:                }
056:                return new AnyThreadPool(pool);
057:            }
058:
059:            private ThreadPool _pool;
060:
061:            public AnyThreadPool(ThreadPool pool) {
062:                _pool = pool;
063:            }
064:
065:            public final anvil.script.ClassType classOf() {
066:                return __class__;
067:            }
068:
069:            public Object toObject() {
070:                return _pool;
071:            }
072:
073:            /// @method getMaxTasks
074:            /// Gets the maximum number of tasks. Sum of free, active and waiting
075:            /// tasks never exceeds this number.
076:            /// @synopsis int getMaxTasks()
077:            public Any m_getMaxTasks() {
078:                return Any.create(_pool.getMaxTasks());
079:            }
080:
081:            /// @method setMaxTasks
082:            /// Gets the maximum number of tasks. Sum of free, active and waiting
083:            /// tasks never exceeds this number.
084:            /// @synopsis ThreadPool setMaxTasks(int maxtask)
085:            public static final Object[] p_setMaxTasks = { "maxTasks" };
086:
087:            public Any m_setMaxTasks(int max) {
088:                if (max < 2) {
089:                    max = 2;
090:                }
091:                _pool.setMaxTasks(max);
092:                return this ;
093:            }
094:
095:            /// @method getMaxThreads
096:            /// Gets the maximum number of threads. No more that the given
097:            /// number of threads are created.
098:            /// @synopsis int getMaxThreads()
099:            public Any m_getMaxThreads() {
100:                return Any.create(_pool.getMaxThreads());
101:            }
102:
103:            /// @method setMaxThreads
104:            /// Sets the maximum number of threads. No more that the given
105:            /// number of threads are created.
106:            /// @synopsis ThreadPool setMaxThreads(int maxthreads)
107:            public static final Object[] p_setMaxThreads = { "maxThreads" };
108:
109:            public Any m_setMaxThreads(int max) {
110:                if (max < 2) {
111:                    max = 2;
112:                }
113:                _pool.setMaxThreads(max);
114:                return this ;
115:            }
116:
117:            /// @method threads
118:            /// Gets the number of threads created.
119:            /// @synopsis int threads()
120:            public Any m_threads() {
121:                return Any.create(_pool.threads());
122:            }
123:
124:            /// @method waiting
125:            /// Gets the number of tasks waiting to be executed.
126:            /// @synopsis int waiting()
127:            public Any m_waiting() {
128:                return Any.create(_pool.waiting());
129:            }
130:
131:            /// @method shutdown
132:            /// Shuts down this thread pool. All threads are closed but
133:            /// the pool remains usable after shutdown.
134:            /// @synopsis ThreadPool shutdown()
135:            public Any m_shutdown() {
136:                _pool.shutdown();
137:                return this ;
138:            }
139:
140:            /// @method spawn
141:            /// Spawns a task. Task may not be immediately executed if
142:            /// all threads are currently in use.
143:            /// @synopsis ThreadPool spawn(object callable, ..parameters)
144:            public static final Object[] p_spawn = { null, "callable",
145:                    "parameters" };
146:
147:            public Any m_spawn(Context context, Any callable, Any[] parameters) {
148:                FunctionTask task = new FunctionTask(context, callable,
149:                        parameters);
150:                _pool.spawn(task);
151:                return this ;
152:            }
153:
154:            public static final anvil.script.compiler.NativeClass __class__ = new anvil.script.compiler.NativeClass(
155:                    "ThreadPool",
156:                    AnyThreadPool.class,
157:                    //DOC{{
158:                    ""
159:                            + " @class ThreadPool\n"
160:                            + " ThreadPool is pool of re-usable threads. \n"
161:                            + " Re-use of threads is beneficial as the relative heavy-weight \n"
162:                            + " creation of thread can be avoided.\n"
163:                            + " @constructor ThreadPool\n"
164:                            + " Creates new thread pool.\n"
165:                            + " @synopsis ThreadPool()\n"
166:                            + " @synopsis ThreadPool(string name)\n"
167:                            + " @synopsis ThreadPool(string name, int maxthreads)\n"
168:                            + " @synopsis ThreadPool(string name, int maxthreads, int maxtasks)\n"
169:                            + " @method getMaxTasks\n"
170:                            + " Gets the maximum number of tasks. Sum of free, active and waiting\n"
171:                            + " tasks never exceeds this number.\n"
172:                            + " @synopsis int getMaxTasks()\n"
173:                            + " @method setMaxTasks\n"
174:                            + " Gets the maximum number of tasks. Sum of free, active and waiting\n"
175:                            + " tasks never exceeds this number.\n"
176:                            + " @synopsis ThreadPool setMaxTasks(int maxtask)\n"
177:                            + " @method getMaxThreads\n"
178:                            + " Gets the maximum number of threads. No more that the given\n"
179:                            + " number of threads are created.\n"
180:                            + " @synopsis int getMaxThreads()\n"
181:                            + " @method setMaxThreads\n"
182:                            + " Sets the maximum number of threads. No more that the given\n"
183:                            + " number of threads are created.\n"
184:                            + " @synopsis ThreadPool setMaxThreads(int maxthreads)\n"
185:                            + " @method threads\n"
186:                            + " Gets the number of threads created.\n"
187:                            + " @synopsis int threads()\n"
188:                            + " @method waiting\n"
189:                            + " Gets the number of tasks waiting to be executed.\n"
190:                            + " @synopsis int waiting()\n"
191:                            + " @method shutdown\n"
192:                            + " Shuts down this thread pool. All threads are closed but\n"
193:                            + " the pool remains usable after shutdown.\n"
194:                            + " @synopsis ThreadPool shutdown()\n"
195:                            + " @method spawn\n"
196:                            + " Spawns a task. Task may not be immediately executed if\n"
197:                            + " all threads are currently in use.\n"
198:                            + " @synopsis ThreadPool spawn(object callable, ..parameters)\n"
199:            //}}DOC
200:            );
201:            static {
202:                RuntimeModule.class.getName();
203:            }
204:
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.