Skip to content

Commit 35c30a2

Browse files
committed
Changed MathWorker logic
1 parent 5e30e6c commit 35c30a2

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

highcpu/src/main/java/com/github/chrishantha/sample/highcpu/MathWorker.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ public MathWorker() {
2727

2828
@Override
2929
public void run() {
30+
BigDecimal bigDecimal = BigDecimal.ZERO;
3031
while (true) {
31-
BigDecimal sum = BigDecimal.ZERO;
32-
for (int i = 0; i <= Integer.MAX_VALUE; i++) {
33-
double value = Math.atan(Math.sqrt(Math.pow(random.nextInt(10), random.nextDouble())));
34-
sum = sum.add(BigDecimal.valueOf(value));
32+
double value = Math.atan(Math.sqrt(Math.pow(random.nextInt(10), random.nextDouble())));
33+
if (random.nextInt(10) > 5) {
34+
bigDecimal = bigDecimal.add(BigDecimal.valueOf(value));
35+
} else {
36+
bigDecimal = bigDecimal.subtract(BigDecimal.valueOf(value));
3537
}
3638
}
3739
}

0 commit comments

Comments
 (0)