Java Doc for ThreadPool.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 Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.sun.portal.util.ThreadPool

ThreadPool
final public class ThreadPool (Code)

ThreadPool is a generic thread pool that manages and recycles threads instead of creating them everytime some task needs to be run on a different thread. Thread pooling saves the virtual machine the work of creating brand new threads for every short-lived task. In addition, it minimizes overhead associated with getting a thread started and cleaning it up after it dies. By creating a pool of threads, a single thread from the pool can be reused any number of times for different tasks.

This reduces response time because a thread is already constructed and started and is simply waiting for its next task. This is particularly useful when using many short-lived tasks. This may not be useful for long-lived tasks.

Another characteristic of this thread pool is that it is fixed in size at the time of construction. All the threads are started, and then each goes into a wait state until a task is assigned to it. If all the threads in the pool are currently assigned a task, the pool is empty and new requests (tasks) will have to wait before being scheduled to run. This is a way to put an upper bound on the amount of resources any pool can use up.

In future, this class may be enhanced to provide support growing the size of the pool at runtime to facilitate dynamic tuning.




Constructor Summary
public  ThreadPool(String poolName, int numThreads, boolean daemon, Logger logger)
    

Constructs a thread pool with the poolName and given number of threads. Another characteristic of this thread pool is that it is fixed in size at the time of construction.


Method Summary
final public  voiddestroy()
     Destroys the thread pool.
final public  StringgetName()
    
final public  voidrun(Runnable task)
     Runs the user-defined task.
final public  voidstopIdleThreads()
     Stops all the idle threads in the pool.
public  StringtoString()
    


Constructor Detail
ThreadPool
public ThreadPool(String poolName, int numThreads, boolean daemon, Logger logger) throws IllegalArgumentException(Code)

Constructs a thread pool with the poolName and given number of threads. Another characteristic of this thread pool is that it is fixed in size at the time of construction. All the threads are started, and then each goes into a wait state until a task is assigned to it.

The size of the pool should be carefully choosen. If the size is too large, there may be excessive context switching and the performance may suffer. If the tasks are fairly distributed between CPU and I/O usage, start with a pool size of 10 per CPU; later experiment and fine-tune for optimal pool size. Ensure that the pool size is configurable at install/runtime.


Parameters:
  poolName - name of the thread pool
Parameters:
  numThreads - maximum number of threads in the thread pool.
Parameters:
  daemon - if true, all threads created will be daemon threads. If false,all threads created will be non-daemon threads.
Parameters:
  logger - logger object to send log messages to.
throws:
  IllegalArgumentException - if poolName is null




Method Detail
destroy
final public void destroy()(Code)
Destroys the thread pool. This stops all the threads, active and idle, in the pool and releases all resources.



getName
final public String getName()(Code)
Returns the name of this thread pool



run
final public void run(Runnable task) throws InterruptedException(Code)
Runs the user-defined task. To enable better debugging or profiling capabilities, the task Runnable should implement toString() to intuitively identify the task.
Parameters:
  task - the user-defined Runnable to be scheduled for execution onthis thread pool
throws:
  InterruptedException - when the thread invoking run is interrupted.



stopIdleThreads
final public void stopIdleThreads()(Code)
Stops all the idle threads in the pool. Note that these stopped threads are no longer availble for future tasks because they are returned to underlying virtual machine. Also note that none of the active threads in the pool are stopped.



toString
public String toString()(Code)
Returns the string representation of this thread pool that includes the name, size and the number of currently idle threads



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.