biz.chitec.quarterback.util
Class ThreadKicker
java.lang.Object
biz.chitec.quarterback.util.ThreadInterface
biz.chitec.quarterback.util.ThreadKicker
- public class ThreadKicker
- extends ThreadInterface
simple thread synchronisator
ThreadKicker is a simplified ThreadInterface. It has the same infrastructure
but sends only marker (so-called "gems") through the list. The producer
puts one gem for each produce() call, the consumer grabs one gem for each
consume() and continues only if at least one gem is available.
To simplify the code, putGem() and grabGem() do not throw IOExceptions but IllegalStateExceptions. In case of simple thread interfaces,
this allows simpler code as no exceptions have to be catched explicitly.
- Version:
- $Id: f7c3b78fa04b8bc9cd1b4a7e011186ae13f0f404 $
- Author:
- Dirk Hillbrecht 1997-1999, chitec/Dirk Hillbrecht 2000,2002, cantamen/Dirk Hillbrecht 2005
Distributed under the terms of the GNU LGPL.
Field Summary |
private static java.lang.Integer |
GEM
|
Constructor Summary |
ThreadKicker()
|
ThreadKicker(int gemcount)
Instantiates the ThreadKicker with the given number of gems in it.
|
Method Summary |
java.lang.Object |
grabGem()
calls consume() and throws IllegalStateException in case of closed kicker.
|
void |
produce()
produces the gem object. |
void |
produce(java.lang.Object o)
overrides inherited implementation: doesn't produce the object, but the gem. |
void |
putGem()
Calls produce() and throws IllegalStateException in case of closed kicker. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
GEM
private static final java.lang.Integer GEM
ThreadKicker
public ThreadKicker()
ThreadKicker
public ThreadKicker(int gemcount)
- Instantiates the ThreadKicker with the given number of gems in it.
This constructor allows easy implementation of a simple semaphore: A thread has to catch a gem before proceeding and puts it back after leaving the semaphored
section.
- Parameters:
gemcount
- Number of gems to be put initially into the queue.
produce
public void produce()
throws java.io.IOException
- produces the gem object.
- Throws:
java.io.IOException
produce
public void produce(java.lang.Object o)
throws java.io.IOException
- overrides inherited implementation: doesn't produce the object, but the gem.
- Overrides:
produce
in class ThreadInterface
- Throws:
java.io.IOException
putGem
public void putGem()
- Calls produce() and throws IllegalStateException in case of closed kicker.
grabGem
public java.lang.Object grabGem()
- calls consume() and throws IllegalStateException in case of closed kicker.
Will always return the gem (as does consume()), as nothing else can be
stored.