Copyright 2011-09-18 Werner Randelshofer

ch.randelshofer.util
Class FixedConcurrentDispatcher

java.lang.Object
  extended by ch.randelshofer.util.FixedConcurrentDispatcher
All Implemented Interfaces:
Dispatcher

public class FixedConcurrentDispatcher
extends java.lang.Object
implements Dispatcher

A concurrentDispatcher with a fixed number of prealocated threads.

Version:
1.1 2006-07-18 Changed thread notification behaviour.
1.0 March 4, 2006 Created.
Author:
Werner Randelshofer

Constructor Summary
FixedConcurrentDispatcher()
          Creates a new FixedConcurrentDispatcher and sets the priority of the processor thread to java.lang.Thread.NORM_PRIORITY and with the available number of processors in the thread pool.
FixedConcurrentDispatcher(int priority, int threadCount)
          Creates a new FixedConcurrentDispatcher.
 
Method Summary
 void dispatch(java.lang.Runnable runner)
          Enqueues the Runnable object, and executes it on a processor thread.
 void enqueue(java.lang.Runnable runner)
          Enqueues the Runnable object but does not grant that it is being executed.
 void join()
          Joins all workers of the dispatcher.
protected  void processEvents()
          This method dequeues all Runnable objects from the queue and executes them.
 void start()
          Starts all workers of the dispatcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedConcurrentDispatcher

public FixedConcurrentDispatcher()
Creates a new FixedConcurrentDispatcher and sets the priority of the processor thread to java.lang.Thread.NORM_PRIORITY and with the available number of processors in the thread pool.


FixedConcurrentDispatcher

public FixedConcurrentDispatcher(int priority,
                                 int threadCount)
Creates a new FixedConcurrentDispatcher.

Parameters:
priority - The priority of the processor thread.
threadCount - The maximal number of concurrent threads in the thread pool.
Method Detail

dispatch

public void dispatch(java.lang.Runnable runner)
Enqueues the Runnable object, and executes it on a processor thread.

Specified by:
dispatch in interface Dispatcher

processEvents

protected void processEvents()
This method dequeues all Runnable objects from the queue and executes them. The method returns when the queue is empty.


join

public void join()
Joins all workers of the dispatcher.

Specified by:
join in interface Dispatcher

enqueue

public void enqueue(java.lang.Runnable runner)
Enqueues the Runnable object but does not grant that it is being executed.


start

public void start()
Starts all workers of the dispatcher.


Copyright 2011-09-18 Werner Randelshofer