public class GridCountDownCallback extends Object
Sample usage::
GridCountDownCallback countDownCb = new GridCountDownCallback(
n, //internal counter is initiated with n
() -> doSomething() //callback
);
//each call of countDown() decrements internal counter
//doSomething() will be executed after counter reaches 0
for (int i = 0; i < n; i++)
new Thread(() -> countDownCb.countDown()).start();
Usage with execution threshold::
GridCountDownCallback countDownCb = new GridCountDownCallback(
n, //internal counter is initiated with n
() -> doSomething(), //callback
n/2 //execution threshold is initiated with n/2
);
//a half of calls of countDown() increase execution counter, so it reaches threshold and callback executes.
//doSomething() will be executed after n threads will perform countDown()
for (int i = 0; i < n; i++)
new Thread(() -> countDownCb.countDown(n % 2 == 0)).start();
| Constructor and Description |
|---|
GridCountDownCallback(int initCnt,
Runnable cb)
Constructor.
|
GridCountDownCallback(int initCnt,
Runnable cb,
int executionThreshold)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
countDown()
Decrements the internal counter.
|
void |
countDown(boolean doIncreaseExecutionCounter)
Decrements the internal counter.
|
public GridCountDownCallback(int initCnt,
Runnable cb,
int executionThreshold)
initCnt - count of invocations of countDown(boolean).cb - callback which will be executed after initialCount
invocations of countDown(boolean).executionThreshold - minimal count of really performed operations to execute callback.public GridCountDownCallback(int initCnt,
Runnable cb)
initCnt - count of invocations of countDown(boolean).cb - callback which will be executed after initialCount
invocations of countDown(boolean).public void countDown(boolean doIncreaseExecutionCounter)
doIncreaseExecutionCounter - whether to increase execution counterpublic void countDown()
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.8.1 Release Date : May 21 2020