StrictQueue.java
net.minecraft.util.thread.StrictQueue
信息
- 全限定名:net.minecraft.util.thread.StrictQueue
- 类型:public interface
- 包:net.minecraft.util.thread
- 源码路径:src/main/java/net/minecraft/util/thread/StrictQueue.java
- 起始行号:L9
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
-
net.minecraft.util.thread.StrictQueue.FixedPriorityQueue- 类型:
class - 修饰符:
public static final - 源码定位:
L18 - 说明:
TODO
- 类型:
-
net.minecraft.util.thread.StrictQueue.QueueStrictQueue- 类型:
class - 修饰符:
public static final - 源码定位:
L67 - 说明:
TODO
- 类型:
-
net.minecraft.util.thread.StrictQueue.RunnableWithPriority- 类型:
record - 修饰符:
public - 源码定位:
L95 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
Runnable pop() @ L10
- 方法名:pop
- 源码定位:L10
- 返回类型:Runnable
- 修饰符:package-private
参数:
- 无
说明:
TODO
boolean push(T t) @ L12
- 方法名:push
- 源码定位:L12
- 返回类型:boolean
- 修饰符:package-private
参数:
- t: T
说明:
TODO
boolean isEmpty() @ L14
- 方法名:isEmpty
- 源码定位:L14
- 返回类型:boolean
- 修饰符:package-private
参数:
- 无
说明:
TODO
int size() @ L16
- 方法名:size
- 源码定位:L16
- 返回类型:int
- 修饰符:package-private
参数:
- 无
说明:
TODO
代码
public interface StrictQueue<T extends Runnable> {
@Nullable Runnable pop();
boolean push(final T t);
boolean isEmpty();
int size();
public static final class FixedPriorityQueue implements StrictQueue<StrictQueue.RunnableWithPriority> {
private final Queue<Runnable>[] queues;
private final AtomicInteger size = new AtomicInteger();
public FixedPriorityQueue(int size) {
this.queues = new Queue[size];
for (int i = 0; i < size; i++) {
this.queues[i] = Queues.newConcurrentLinkedQueue();
}
}
@Override
public @Nullable Runnable pop() {
for (Queue<Runnable> queue : this.queues) {
Runnable task = queue.poll();
if (task != null) {
this.size.decrementAndGet();
return task;
}
}
return null;
}
public boolean push(StrictQueue.RunnableWithPriority task) {
int priority = task.priority;
if (priority < this.queues.length && priority >= 0) {
this.queues[priority].add(task);
this.size.incrementAndGet();
return true;
} else {
throw new IndexOutOfBoundsException(
String.format(Locale.ROOT, "Priority %d not supported. Expected range [0-%d]", priority, this.queues.length - 1)
);
}
}
@Override
public boolean isEmpty() {
return this.size.get() == 0;
}
@Override
public int size() {
return this.size.get();
}
}
public static final class QueueStrictQueue implements StrictQueue<Runnable> {
private final Queue<Runnable> queue;
public QueueStrictQueue(Queue<Runnable> queue) {
this.queue = queue;
}
@Override
public @Nullable Runnable pop() {
return this.queue.poll();
}
@Override
public boolean push(Runnable t) {
return this.queue.add(t);
}
@Override
public boolean isEmpty() {
return this.queue.isEmpty();
}
@Override
public int size() {
return this.queue.size();
}
}
public record RunnableWithPriority(int priority, Runnable task) implements Runnable {
@Override
public void run() {
this.task.run();
}
}
}引用的其他类
- 无