版本更新至:3.76

调整:开发框架改为 Gradle
新增:Language2 工具新增 [book] 类型
This commit is contained in:
坏黑
2018-03-10 21:13:05 +08:00
parent 6439e4b780
commit ad1a21196f
238 changed files with 1686 additions and 1132 deletions

View File

@@ -0,0 +1,85 @@
package me.skymc.taboolib.thread;
import java.util.*;
public class ThreadUtils {
private static PoolWorker[] threads;
private static LinkedList<Runnable> queue = new LinkedList<>();
/**
* 构造方法
*
* @param number 线程数量
*/
public ThreadUtils(int number) {
threads = new PoolWorker[number];
for (int i = 0; i < number; i++) {
threads[i] = new PoolWorker();
threads[i].setName("TabooLib WorkThread - " + i);
threads[i].start();
}
}
/**
* 停止工作
*
*/
public void stop() {
for (PoolWorker p : threads) {
p.stop();
}
}
/**
* 添加任务
*
* @param r
*/
public void execute(Runnable r) {
// 线程锁
synchronized (queue) {
// 添加任务
queue.addLast(r);
// 开始任务
queue.notify();
}
}
private class PoolWorker extends Thread {
@Override
public void run() {
Runnable runnable;
while (true) {
// 线程锁
synchronized (queue) {
// 如果任务为空
while (queue.isEmpty()) {
// 等待任务
try {
queue.wait();
}
catch (InterruptedException e) {
}
}
// 获取任务
runnable = queue.removeFirst();
}
// 运行任务
try {
runnable.run();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
}