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