mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-12 20:07:35 +00:00
up 线程管理
This commit is contained in:
1 parent
adbc160397
commit
d311b81805
6 files changed
+58
-92
No files matched your search
@@ -81,7 +81,6 @@ public class DataSql {
|
||||
* 数据库文件
|
||||
*/
|
||||
public static File sqlFile;
|
||||
private static boolean isRun;
|
||||
/**
|
||||
* 数据库链接对象
|
||||
*/
|
||||
@@ -731,26 +730,24 @@ public class DataSql {
|
||||
*/
|
||||
public static void start() {
|
||||
init();
|
||||
Thread thread = new Thread(DataSql::run);
|
||||
isRun = true;
|
||||
thread.start();
|
||||
new Thread(DataSql::run).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止数据库
|
||||
*/
|
||||
public static void stop() {
|
||||
isRun = false;
|
||||
semaphore.release();
|
||||
}
|
||||
|
||||
private static void run() {
|
||||
AllMusic.log.data("数据库线程启动");
|
||||
Runnable runnable;
|
||||
while (isRun) {
|
||||
while (AllMusic.isRun) {
|
||||
try {
|
||||
semaphore.acquire();
|
||||
if (!isRun)
|
||||
return;
|
||||
if (!AllMusic.isRun)
|
||||
break;
|
||||
do {
|
||||
runnable = tasks.poll();
|
||||
if (runnable != null) {
|
||||
@@ -762,5 +759,6 @@ public class DataSql {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
AllMusic.log.data("数据库线程关闭");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user