mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-08 11:50:36 +01:00
counter thread provider should never update partitions
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
95fd6e7c81
commit
0934c8ef16
@ -1,7 +1,5 @@
|
|||||||
package net.minestom.server.thread;
|
package net.minestom.server.thread;
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.Cache;
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -12,12 +10,11 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
public interface ThreadProvider<T> {
|
public interface ThreadProvider<T> {
|
||||||
static <T> @NotNull ThreadProvider<T> counter() {
|
static <T> @NotNull ThreadProvider<T> counter() {
|
||||||
return new ThreadProvider<>() {
|
return new ThreadProvider<>() {
|
||||||
private final Cache<T, Integer> cache = Caffeine.newBuilder().weakKeys().build();
|
|
||||||
private final AtomicInteger counter = new AtomicInteger();
|
private final AtomicInteger counter = new AtomicInteger();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int findThread(@NotNull T partition) {
|
public int findThread(@NotNull T partition) {
|
||||||
return cache.get(partition, i -> counter.getAndIncrement());
|
return counter.getAndIncrement();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user