Skip to content

Commit

Permalink
Change volatile long to AtomicLong (thanks Radovan)
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0ffrey committed Aug 25, 2018
1 parent 210bbc6 commit b6b4229
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -19,6 +19,7 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicLong;

import org.optaplanner.core.api.score.Score;
import org.optaplanner.core.impl.heuristic.move.Move;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class MoveThreadRunner<Solution_> implements Runnable {
private final boolean assertShadowVariablesAreNotStaleAfterStep;

private InnerScoreDirector<Solution_> scoreDirector = null;
private volatile long calculationCount = -1L;
private AtomicLong calculationCount = new AtomicLong(-1);

public MoveThreadRunner(String logIndentation, int moveThreadIndex, boolean evaluateDoable,
BlockingQueue<MoveThreadOperation<Solution_>> operationQueue,
Expand Down Expand Up @@ -99,7 +100,7 @@ public void run() {
} else if (operation instanceof DestroyOperation) {
logger.trace("{} Move thread ({}) destroy: step index ({}).",
logIndentation, moveThreadIndex, stepIndex);
calculationCount = scoreDirector.getCalculationCount();
calculationCount.set(scoreDirector.getCalculationCount());
break;
} else if (operation instanceof ApplyStepOperation) {
// TODO Performance gain with specialized 2-phase cyclic barrier:
Expand Down Expand Up @@ -188,6 +189,7 @@ protected void predictWorkingStepScore(Move<Solution_> step, Score score) {
* @return at least 0
*/
public long getCalculationCount() {
long calculationCount = this.calculationCount.get();
if (calculationCount == -1L) {
logger.info("{}Score calculation speed will be too low"
+ " because move thread ({})'s destroy wasn't processed soon enough.", logIndentation);
Expand Down

0 comments on commit b6b4229

Please sign in to comment.