Java Doc for Parallelizer.java in  » Template-Engine » ostermillerutils » com » Ostermiller » 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 » Template Engine » ostermillerutils » com.Ostermiller.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.Ostermiller.util.Parallelizer

Parallelizer
public class Parallelizer (Code)
Runs multiple jobs in parallel, n threads at a time, and waits until all threads are complete before continuing.

Typically, Parallelizer would be used to run each of the items- in a for loop at the same time. For example the following for loop:

 for (int i=0; i<10; i++){
 System.out.println("Hello World " + i);
 }
 System.out.println("done");
 
To this:
 Parallelizer parallelizer = new Parallelizer();
 for (int i=0; i<10; i++){
 final int j = i;
 parallelizer.run(
 new Runnable(){
 System.out.println("Hello World " + j);
 }
 );
 }
 parallelizer.join();
 System.out.println("done");
 More information about this class is available from ostermiller.org.

author:
   Matt Conway - http://simplygenius.com/
author:
   Stephen Ostermiller - http://ostermiller.org/contact.pl?regarding=Java+Utilities
since:
   ostermillerutils 1.05.00


Field Summary
final public static  intINFINITE_THREAD_LIMIT
     Constant that may be passed concurrentThreadLimit argument of the constructor indicating that no limit should be placed on the number of threads that are allowed to run concurrently.

Constructor Summary
public  Parallelizer()
     Create a new Parallelizer with no limit on the number of threads that will be allowed to be run concurrently.
public  Parallelizer(int concurrentThreadLimit)
     Create a new Parallelizer with the specified limit on the number of threads that will be allowed to be run concurrently.

Method Summary
public  booleandone()
     Return true iff all jobs that have been requested to run in this Parallelizer have completed.
public  voiddumpStack()
     Dump the stack of each running thread.
public  Thread[]getRunningThreads()
     Gets a list of all running threads.
public  voidinterrupt()
     All currently running threads will be interrupted.
public  voidjoin()
     Block until all the jobs in this Parallelizer have run and then return.
public  voidrun(Runnable job)
     Run the given job.
public  voidrun(Runnable job, String threadName)
     Run the given job.
public  voidrun(ThreadGroup threadGroup, Runnable job)
     Run the given job.
public  voidrun(ThreadGroup threadGroup, Runnable job, String threadName)
     Run the given job.
public  voidrun(ThreadGroup threadGroup, Runnable job, String threadName, long stackSize)
     Run the given job.

Field Detail
INFINITE_THREAD_LIMIT
final public static int INFINITE_THREAD_LIMIT(Code)
Constant that may be passed concurrentThreadLimit argument of the constructor indicating that no limit should be placed on the number of threads that are allowed to run concurrently.
since:
   ostermillerutils 1.05.00




Constructor Detail
Parallelizer
public Parallelizer()(Code)
Create a new Parallelizer with no limit on the number of threads that will be allowed to be run concurrently.
since:
   ostermillerutils 1.05.00



Parallelizer
public Parallelizer(int concurrentThreadLimit)(Code)
Create a new Parallelizer with the specified limit on the number of threads that will be allowed to be run concurrently.

When the concurrent thread limit is reached and the parallelizer gets a new thread to run, the new thread will be queued until a thread finishes.
Parameters:
  concurrentThreadLimit - number of threads that will be allowedto run simultaneously or INFINITE_THREAD_LIMIT for no limit.
throws:
  IllegalArgumentException - if concurrentThreadLimit not a wholenumber or INFINITE_THREAD_LIMIT
since:
   ostermillerutils 1.05.00





Method Detail
done
public boolean done()(Code)
Return true iff all jobs that have been requested to run in this Parallelizer have completed.

If this method throws an error, that error may be handled and this method may be called again as it will not re-throw the same instance of the error. Whether all jobs are done or not.
throws:
  Error - if any of the running threads has thrown an Error.
since:
   ostermillerutils 1.05.00




dumpStack
public void dumpStack()(Code)
Dump the stack of each running thread.

If this method throws an error, that error may be handled and this method may be called again as it will not re-throw the same instance of the error.
throws:
  Error - if any of the running threads has thrown an Error.
since:
   ostermillerutils 1.05.00




getRunningThreads
public Thread[] getRunningThreads()(Code)
Gets a list of all running threads. There may be jobs that are queued and do not yet have threads. These job are not returned.

If this method throws an error, that error may be handled and this method may be called again as it will not re-throw the same instance of the error.
throws:
  Error - if any of the running threads has thrown an Error. an array of all currently running threads.
since:
   ostermillerutils 1.05.00




interrupt
public void interrupt()(Code)
All currently running threads will be interrupted. The threads interrupted threads may die, causing jobs that were queued but not yet started, to start.

If this method throws an error, that error may be handled and this method may be called again as it will not re-throw the same instance of the error.
throws:
  Error - if any of the running threads has thrown an Error.
since:
   ostermillerutils 1.05.00




join
public void join() throws InterruptedException(Code)
Block until all the jobs in this Parallelizer have run and then return.

If this method throws an exception or an error, that exception or error may be handled and this method may be called again as it will not re-throw the same instance of the exception or error.
throws:
  InterruptedException - if interrupted while waiting.
throws:
  RuntimeException - any running thread throws or has thrown a runtime exception.
throws:
  Error - if any of the running threads throws or has thrown an Error.
since:
   ostermillerutils 1.05.00




run
public void run(Runnable job)(Code)
Run the given job. The given job is either run immediately or if the max number of concurrent jobs are already running, it is queued to be run when some job is finished.

If this method throws an error, that error may be handled and this method may be called again as it will not re-throw the same instance of the error.
Parameters:
  job - job which is to be run in parallel with other jobs.
throws:
  Error - if any thread that is already running has thrown an Error.
throws:
  NullPointerException - if job is null.
since:
   ostermillerutils 1.05.00




run
public void run(Runnable job, String threadName)(Code)
Run the given job. The given job is either run immediately or if the max number of concurrent jobs are already running, it is queued to be run when some job is finished.

If this method throws an error, that error may be handled and this method may be called again as it will not re-throw the same instance of the error.
Parameters:
  job - job which is to be run in parallel with other jobs.
Parameters:
  threadName - name for the thread that will be created to run the job (null for auto generated thread name)
throws:
  Error - if any thread that is already running has thrown an Error.
throws:
  NullPointerException - if job is null.
since:
   ostermillerutils 1.05.00




run
public void run(ThreadGroup threadGroup, Runnable job)(Code)
Run the given job. The given job is either run immediately or if the max number of concurrent jobs are already running, it is queued to be run when some job is finished.

If this method throws an error, that error may be handled and this method may be called again as it will not re-throw the same instance of the error.
Parameters:
  threadGroup - group in which this job should be run (null for default group).
Parameters:
  job - job which is to be run in parallel with other jobs.
throws:
  Error - if any thread that is already running has thrown an Error.
throws:
  NullPointerException - if job is null.
since:
   ostermillerutils 1.05.00




run
public void run(ThreadGroup threadGroup, Runnable job, String threadName)(Code)
Run the given job. The given job is either run immediately or if the max number of concurrent jobs are already running, it is queued to be run when some job is finished.

If this method throws an error, that error may be handled and this method may be called again as it will not re-throw the same instance of the error.
Parameters:
  threadGroup - group in which this job should be run (null for default group).
Parameters:
  job - job which is to be run in parallel with other jobs.
Parameters:
  threadName - name for the thread that will be created to run the job (null for auto generated thread name)
throws:
  Error - if any thread that is already running has thrown an Error.
throws:
  NullPointerException - if job is null.
since:
   ostermillerutils 1.05.00




run
public void run(ThreadGroup threadGroup, Runnable job, String threadName, long stackSize)(Code)
Run the given job. The given job is either run immediately or if the max number of concurrent jobs are already running, it is queued to be run when some job is finished.

If this method throws an error, that error may be handled and this method may be called again as it will not re-throw the same instance of the error.
Parameters:
  threadGroup - group in which this job should be run (null for default group).
Parameters:
  job - job which is to be run in parallel with other jobs.
Parameters:
  threadName - name for the thread that will be created to run the job (null for auto generated thread name)
Parameters:
  stackSize - system dependent stack size suggestion for thread creation (0 for default stack size).
throws:
  Error - if any thread that is already running has thrown an Error.
throws:
  NullPointerException - if job is null.
since:
   ostermillerutils 1.05.00




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.