Skip to content

Commit

Permalink
fix(cpu): disabled reset thread as it's not doing much
Browse files Browse the repository at this point in the history
  • Loading branch information
seailz committed Sep 19, 2023
1 parent 53d2729 commit 44a321b
Showing 1 changed file with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,29 @@ public Bucket(String id, int limit, int remaining, long reset, double resetAfter
this.resetAfter = new AtomicLong(resetAfterMillis);
this.debug = debug;
// Start the reset thread
new Thread(() -> {
while (true) {
if (remaining != 0) {
continue;
}
long currentReset = atomicReset.get();
long currentTime = System.currentTimeMillis();

if (currentReset > currentTime) {
try {
Thread.sleep(currentReset - currentTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (atomicReset.compareAndSet(currentReset, System.currentTimeMillis() + resetAfterMillis)) {
if (debug) {
System.out.println("Resetting requests for " + id);
}
reset(); // Reset the bucket only if the currentReset is still the same as the one we fetched above.
}
}
}, "djar--bucket-reset").start();
// new Thread(() -> {
// while (true) {
// if (remaining != 0) {
// continue;
// }
// long currentReset = atomicReset.get();
// long currentTime = System.currentTimeMillis();
//
// if (currentReset > currentTime) {
// try {
// Thread.sleep(currentReset - currentTime);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// if (atomicReset.compareAndSet(currentReset, System.currentTimeMillis() + resetAfterMillis)) {
// if (debug) {
// System.out.println("Resetting requests for " + id);
// }
// reset(); // Reset the bucket only if the currentReset is still the same as the one we fetched above.
// }
// }
// }, "djar--bucket-reset").start();
}

public synchronized Bucket update(int limit, int remaining, double reset, float resetAfter) {
Expand Down

0 comments on commit 44a321b

Please sign in to comment.