The im4java Library, Version 1.4.0

org.im4java.process
Class ProcessExecutor

java.lang.Object
  extended by java.util.concurrent.AbstractExecutorService
      extended by java.util.concurrent.ThreadPoolExecutor
          extended by org.im4java.process.ProcessExecutor
All Implemented Interfaces:
java.util.concurrent.Executor, java.util.concurrent.ExecutorService, ProcessEventListener
Direct Known Subclasses:
BatchConverter

public class ProcessExecutor
extends java.util.concurrent.ThreadPoolExecutor
implements ProcessEventListener

This class subclasses ThreadPoolExecutor and implements a pooling-service for threads running processes.

Since:
1.1.0
Version:
$Revision: 1.3 $
Author:
$Author: bablokb $

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
 
Constructor Summary
ProcessExecutor()
          The default constructor creates a fixed-sized thread-pool with corePoolSize == maximumPoolSize.
ProcessExecutor(int pProcs)
          Create a ProcessExecutor with given number of threads for corePoolSize and maximumPoolSize.
 
Method Summary
protected  void afterExecute(java.lang.Runnable r, java.lang.Throwable t)
          Deregister this ProcessExecutor as a ProcessEventListener.
protected  void beforeExecute(java.lang.Thread t, java.lang.Runnable r)
          Register this ProcessExecutor as a ProcessEventListener.
 void destroy()
          Destroy all active processes.
 void processInitiated(ProcessEvent pEvent)
          This method is called at process initiation.
 void processStarted(ProcessEvent pEvent)
          This method is called at process startup.
 void processTerminated(ProcessEvent pEvent)
          This method is called at normal or abnormal process termination.
 java.util.List<java.lang.Runnable> shutdownNow()
          
 
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, terminated
 
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessExecutor

public ProcessExecutor()
The default constructor creates a fixed-sized thread-pool with corePoolSize == maximumPoolSize. The maximum number of concurrently running processes is controlled by the system-property im4java.maxProcs. If unset or if the property has the value auto, the number returned by Runtime.availableProcessors() is used.


ProcessExecutor

public ProcessExecutor(int pProcs)
Create a ProcessExecutor with given number of threads for corePoolSize and maximumPoolSize.

Parameters:
pProcs - Number of concurrently executing processes.
Method Detail

beforeExecute

protected void beforeExecute(java.lang.Thread t,
                             java.lang.Runnable r)
Register this ProcessExecutor as a ProcessEventListener.

Overrides:
beforeExecute in class java.util.concurrent.ThreadPoolExecutor

afterExecute

protected void afterExecute(java.lang.Runnable r,
                            java.lang.Throwable t)
Deregister this ProcessExecutor as a ProcessEventListener.

Overrides:
afterExecute in class java.util.concurrent.ThreadPoolExecutor

processInitiated

public void processInitiated(ProcessEvent pEvent)
This method is called at process initiation.

Specified by:
processInitiated in interface ProcessEventListener

processStarted

public void processStarted(ProcessEvent pEvent)
This method is called at process startup. This method is called at process startup. We keep track of processes so we can destroy them if necessary.

Specified by:
processStarted in interface ProcessEventListener

processTerminated

public void processTerminated(ProcessEvent pEvent)
This method is called at normal or abnormal process termination. This method is called at normal or abnormal process termination.

Specified by:
processTerminated in interface ProcessEventListener

shutdownNow

public java.util.List<java.lang.Runnable> shutdownNow()

Specified by:
shutdownNow in interface java.util.concurrent.ExecutorService
Overrides:
shutdownNow in class java.util.concurrent.ThreadPoolExecutor

destroy

public void destroy()
Destroy all active processes.


The im4java Library, Version 1.4.0

Released under the LGPL, (c) Bernhard Bablok 2008-2010
Homepage: http://im4java.sourceforge.net/