📄 operationsqueue.java
字号:
package com.ismyway.anyview.others;
import com.ismyway.util.ArrayList;
public class OperationsQueue extends Thread {
private volatile boolean running = true;
private final ArrayList operations = new ArrayList();
private static OperationsQueue instance;
public synchronized static OperationsQueue getInstance() {
if (instance == null || instance.running == false)
instance = new OperationsQueue();
return instance;
}
private OperationsQueue() {
this.start();
}
public void enqueueOperation(Operation nextOperation) {
if (this.operations.size() > 10) {
return;
}
operations.add(nextOperation);
}
//stop the thread
public void abort() {
running = false;
this.operations.clear();
}
public boolean isIdle() {
if (this.operations.size() > 0 || opExecuting)
return false;
return true;
}
private boolean opExecuting;
public void run() {
while (running) {
while (operations.size() > 0) {
try {
Operation operation = (Operation) operations.get(0);
operations.remove(0);
opExecuting = true;
operation.execute();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
opExecuting = false;
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -