|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.curjent.agent.ReusableTask
public class ReusableTask
Source for a task that can be used concurrently by multiple threads. Since one task is used by multiple threads, the task is responsible for synchronizing access to any mutable state.
This implementation is not thread-safe.
Field Summary | |
---|---|
private int |
count
Keeps track of how many times the task has been acquired. |
private int |
max
Maximum number of times the task can be acquired. |
private Object |
task
Single task used by multiple threads of execution. |
Constructor Summary | |
---|---|
ReusableTask(Object task,
int max)
Initializes this instance with the one reusable task and the maximum number of times it can be acquired. |
Method Summary | |
---|---|
Object |
acquire()
Increments the number of outstanding acquires and returns the reusable task. |
void |
release(Object task)
Decrements the number of outstanding acquires. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final Object task
private final int max
private int count
0
and max
, inclusive.
Constructor Detail |
---|
public ReusableTask(Object task, int max)
max
is greater than
1
, the given task
must be thread-safe.
NullPointerException
- task
is null
.
IllegalArgumentException
- max
is 0
or
negative.Method Detail |
---|
public Object acquire() throws Throwable
null
if max
has been reached.
acquire
in interface AgentTasks
Throwable
- An unexpected error.Agent.newInstance(AgentLoader, Class[], AgentTasks, Class)
public void release(Object task) throws Throwable
release
in interface AgentTasks
IllegalStateException
- The given task
is not the same
as the task
this instance was constructed with.
IllegalStateException
- The number of releases has exceeded the
number of outstanding acquires.
Throwable
- An unexpected error.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |