Java Doc for ThreadPool.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » jj2000 » j2k » 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 » 6.0 JDK Modules » Java Advanced Imaging » jj2000.j2k.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   jj2000.j2k.util.ThreadPool

ThreadPool
public class ThreadPool (Code)
This class implements a thread pool. The thread pool contains a set of threads which can be given work to do.

If the Java Virtual Machine (JVM) uses native threads, then the different threads will be able to execute in different processors in parallel on multiprocessors machines. However, under some JVMs and operating systems using native threads is not sufficient to allow the JVM access to multiple processors. This is the case when native threads are implemented using POSIX threads on lightweight processes (i.e. PTHREAD_SCOPE_PROCESS sopce scheduling), which is the case on most UNIX operating systems. In order to do provide access to multiple processors it is necessary to set the concurrency level to the number of processors or slightly higher. This can be achieved by setting the Java system property with the name defined by CONCURRENCY_PROP_NAME to some non-negative number. This will make use of the 'NativeServices' class and supporting native libraries. See 'NativeServices' for details. See 'CONCURRENCY_PROP_NAME' for the name of the property.

Initially the thread pool contains a user specified number of idle threads. Idle threads can be given a target which is run. While running the target the thread temporarily leaves the idle list. When the target finishes, it joins the idle list again, waiting for a new target. When a target is finished a thread can be notified on a particular object that is given as a lock.

Jobs can be submitted using Runnable interfaces, using the 'runTarget()' methods. When the job is submitted, an idle thread will be obtained, the 'run()' method of the 'Runnable' interface will be executed and when it completes the thread will be returned to the idle list. In general the 'run()' method should complete in a rather short time, so that the threds of the pool are not starved.

If using the non-asynchronous calls to 'runTarget()', it is important that any target's 'run()' method, or any method called from it, does not use non-asynchronous calls to 'runTarget()' on the same thread pool where it was started. Otherwise this could create a dead-lock when there are not enough idle threads.

The pool also has a global error and runtime exception condition (one for 'Error' and one for 'RuntimeException'). If a target's 'run()' method throws an 'Error' or 'RuntimeException' the corresponding exception condition is set and the exception object saved. In any subsequent call to 'checkTargetErrors()' the saved exception object is thrown. Likewise, if a target's 'run()' method throws any other subclass of 'Throwable' a new 'RuntimeException' is created and saved. It will be thrown on a subsequent call to 'checkTargetErrors()'. If more than one exception occurs between calls to 'checkTargetErrors()' only the last one is saved. Any 'Error' condition has precedence on all 'RuntimeException' conditions. The threads in the pool are unaffected by any exceptions thrown by targets.

The only exception to the above is the 'ThreadDeath' exception. If a target's 'run()' method throws the 'ThreadDeath' exception a warning message is printed and the exception is propagated, which will terminate the thread in which it occurs. This could lead to instabilities of the pool. The 'ThreadDeath' exception should never be thrown by the program. It is thrown by the Java(TM) Virtual Machine when Thread.stop() is called. This method is deprecated and should never be called.

All the threads in the pool are "daemon" threads and will automatically terminate when no daemon threads are running.
See Also:   NativeServices
See Also:   ThreadPool.CONCURRENCY_PROP_NAME
See Also:   Runnable
See Also:   Thread
See Also:   Error
See Also:   RuntimeException


Inner Class :class ThreadPoolThread extends Thread

Field Summary
final public static  StringCONCURRENCY_PROP_NAME
    

Constructor Summary
public  ThreadPool(int size, int priority, String name)
     Creates a new thread pool of the given size, thread priority and pool name.

If the Java system property of the name defined by 'CONCURRENCY_PROP_NAME' is set, then an attempt will be made to load the library that supports concurrency setting (see 'NativeServices').


Method Summary
public  voidcheckTargetErrors()
     Checks that no error or runtime exception in any target have occurred so far.
public  voidclearTargetErrors()
     Clears the current target error conditions, if any.
public  intgetSize()
     Returns the size of the pool.
public  booleanrunTarget(Runnable t, Object l)
     Runs the run method of the specified target in an idle thread of this pool.
public  booleanrunTarget(Runnable t, Object l, boolean async)
     Runs the run method of the specified target in an idle thread of this pool.
public  booleanrunTarget(Runnable t, Object l, boolean async, boolean notifyAll)
     Runs the run method of the specified target in an idle thread of this pool.

Field Detail
CONCURRENCY_PROP_NAME
final public static String CONCURRENCY_PROP_NAME(Code)
The name of the property that sets the concurrency level: jj2000.j2k.util.ThreadPool.concurrency




Constructor Detail
ThreadPool
public ThreadPool(int size, int priority, String name)(Code)
Creates a new thread pool of the given size, thread priority and pool name.

If the Java system property of the name defined by 'CONCURRENCY_PROP_NAME' is set, then an attempt will be made to load the library that supports concurrency setting (see 'NativeServices'). If that succeds the concurrency level will be set to the specified value. Otherwise a warning is printed.
Parameters:
  size - The size of the pool (number of threads to create in thepool).
Parameters:
  priority - The priority to give to the threads in the pool. Ifless than 'Thread.MIN_PRIORITY' it will be the same as the priority ofthe calling thread.
Parameters:
  name - The name of the pool. If null a default generic name ischosen.
See Also:   NativeServices
See Also:   ThreadPool.CONCURRENCY_PROP_NAME





Method Detail
checkTargetErrors
public void checkTargetErrors()(Code)
Checks that no error or runtime exception in any target have occurred so far. If an error or runtime exception has occurred in a target's run method they are thrown by this method.
exception:
  Error - If an error condition has been thrown by a target'run()' method.
exception:
  RuntimeException - If a runtime exception has been thrown by atarget 'run()' method.



clearTargetErrors
public void clearTargetErrors()(Code)
Clears the current target error conditions, if any. Note that a thread in the pool might have set the error conditions since the last check and that those error conditions will be lost. Likewise, before returning from this method another thread might set the error conditions. There is no guarantee that no error conditions exist when returning from this method.

In order to ensure that no error conditions exist when returning from this method cooperation from the targets and the thread using this pool is necessary (i.e. currently no targets running or waiting to run).




getSize
public int getSize()(Code)
Returns the size of the pool. That is the number of threads in this pool (idle + busy). The pool's size.



runTarget
public boolean runTarget(Runnable t, Object l)(Code)
Runs the run method of the specified target in an idle thread of this pool. When the target's run method completes, the thread waiting on the lock object is notified, if any. If there is currently no idle thread the method will block until a thread of the pool becomes idle or the calling thread is interrupted.

This method is the same as runTarget(t,l,true,false).
Parameters:
  t - The target. The 'run()' method of this object will be run inan idle thread of the pool.
Parameters:
  l - The lock object. A thread waiting on the lock of the 'l'object will be notified, through the 'notify()' call, when the target'srun method completes. If null no thread is notified. True if the target was submitted to some thread. False if noidle thread could be found and the target was not submitted forexecution.




runTarget
public boolean runTarget(Runnable t, Object l, boolean async)(Code)
Runs the run method of the specified target in an idle thread of this pool. When the target's run method completes, the thread waiting on the lock object is notified, if any. If there is currently no idle thread and the asynchronous mode is not used the method will block until a thread of the pool becomes idle or the calling thread is interrupted. If the asynchronous mode is used then the method will not block and will return false.

This method is the same as runTarget(t,l,async,false).
Parameters:
  t - The target. The 'run()' method of this object will be run inan idle thread of the pool.
Parameters:
  l - The lock object. A thread waiting on the lock of the 'l'object will be notified, through the 'notify()' call, when the target'srun method completes. If null no thread is notified.
Parameters:
  async - If true the asynchronous mode will be used. True if the target was submitted to some thread. False if noidle thread could be found and the target was not submitted forexecution.




runTarget
public boolean runTarget(Runnable t, Object l, boolean async, boolean notifyAll)(Code)
Runs the run method of the specified target in an idle thread of this pool. When the target's run method completes, the thread waiting on the lock object is notified, if any. If there is currently no idle thread and the asynchronous mode is not used the method will block until a thread of the pool becomes idle or the calling thread is interrupted. If the asynchronous mode is used then the method will not block and will return false.
Parameters:
  t - The target. The 'run()' method of this object will be run inan idle thread of the pool.
Parameters:
  l - The lock object. A thread waiting on the lock of the 'l'object will be notified, through the 'notify()' call, when the target'srun method completes. If null no thread is notified.
Parameters:
  async - If true the asynchronous mode will be used.
Parameters:
  notifyAll - If true, threads waiting on the lock of the 'l' objectwill be notified trough the 'notifyAll()' instead of the normal'notify()' call. This is not normally needed. True if the target was submitted to some thread. False if noidle thread could be found and the target was not submitted forexecution.



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.