Skip to content

Commit

Permalink
using Math.ceil() instead of BigDecimal rounding when calculating sec…
Browse files Browse the repository at this point in the history
…onds
  • Loading branch information
grofoli committed Jan 6, 2021
1 parent e380b79 commit 6b52104
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import net.javacrumbs.shedlock.support.LockException;
import net.javacrumbs.shedlock.support.annotation.NonNull;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
Expand Down Expand Up @@ -72,7 +70,7 @@ public Optional<SimpleLock> lock(@NonNull LockConfiguration lockConfiguration) {
}

private static final class EtcdLock extends AbstractSimpleLock {
private static final BigDecimal MILLIS_IN_SECOND = BigDecimal.valueOf(1000);
private static final long MILLIS_IN_SECOND = 1000L;
private final String key;
private Long successLeaseId;
private final EtcdTemplate etcdTemplate;
Expand Down Expand Up @@ -121,9 +119,7 @@ public void doUnlock() {
}

private long getSecondsUntil(Instant instant) {
return BigDecimal.valueOf(getMsUntil(instant))
.divide(MILLIS_IN_SECOND, RoundingMode.CEILING)
.longValue();
return (long) Math.ceil((double) getMsUntil(instant) / MILLIS_IN_SECOND);
}

private long getMsUntil(Instant instant) {
Expand Down

0 comments on commit 6b52104

Please sign in to comment.