Update devlok-queue
This commit is contained in:
parent
9122d53921
commit
fea8126174
@ -12,7 +12,7 @@ allprojects {
|
||||
apply(plugin = "com.github.johnrengelman.shadow")
|
||||
|
||||
group = "de.weapie"
|
||||
version = "2024.07.08-03"
|
||||
version = "2024.07.12-01"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@ -12,12 +12,21 @@ public class TaskProcessor {
|
||||
private TaskQueue taskQueue;
|
||||
private ExecutorService executor;
|
||||
private long delayMillis;
|
||||
private long delayEmptyMillis;
|
||||
private boolean running = true;
|
||||
|
||||
public TaskProcessor(TaskQueue taskQueue, long delayMillis) {
|
||||
this.taskQueue = taskQueue;
|
||||
this.executor = Executors.newSingleThreadExecutor();
|
||||
this.delayMillis = delayMillis;
|
||||
this.delayEmptyMillis = delayMillis;
|
||||
}
|
||||
|
||||
public TaskProcessor(TaskQueue taskQueue, long delayMillis, long delayEmptyMillis) {
|
||||
this.taskQueue = taskQueue;
|
||||
this.executor = Executors.newSingleThreadExecutor();
|
||||
this.delayMillis = delayMillis;
|
||||
this.delayEmptyMillis = delayEmptyMillis;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
@ -31,6 +40,7 @@ public class TaskProcessor {
|
||||
}
|
||||
|
||||
if(this.taskQueue.size() < this.taskQueue.getThreshold()) {
|
||||
TimeUnit.MILLISECONDS.sleep(this.delayEmptyMillis);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package de.weapie.devlok.queue.tasks;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.function.Consumer;
|
||||
@ -13,6 +12,7 @@ public class TaskQueue {
|
||||
|
||||
private BlockingQueue<Task> queue = new LinkedBlockingQueue<>();
|
||||
private final int delayInMillis;
|
||||
private final int delayEmptyInMillis;
|
||||
@Getter
|
||||
private final int threshold;
|
||||
@Getter
|
||||
@ -40,7 +40,7 @@ public class TaskQueue {
|
||||
|
||||
public void startProcessing() {
|
||||
if (!this.processing) {
|
||||
this.taskProcessor = new TaskProcessor(this, delayInMillis);
|
||||
this.taskProcessor = new TaskProcessor(this, delayInMillis, delayEmptyInMillis);
|
||||
this.taskProcessor.start();
|
||||
this.processing = true;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user