优化子线程单例模式;
This commit is contained in:
parent
bb006641b0
commit
355b6a119b
@ -11,14 +11,14 @@ import java.util.Vector;
|
|||||||
/**
|
/**
|
||||||
* 更新扩展词典子线程类
|
* 更新扩展词典子线程类
|
||||||
*/
|
*/
|
||||||
public class UpdateKeeper implements Runnable {
|
public class UpdateThread implements Runnable {
|
||||||
private static final long INTERVAL = 30000L; // 循环等待时间
|
private static final long INTERVAL = 30000L; // 循环等待时间
|
||||||
private Vector<UpdateJob> filterFactorys; // 更新任务集合
|
private Vector<UpdateJob> filterFactorys; // 更新任务集合
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 私有化构造器,阻止外部进行实例化
|
* 私有化构造器,阻止外部进行实例化
|
||||||
*/
|
*/
|
||||||
private UpdateKeeper() {
|
private UpdateThread() {
|
||||||
this.filterFactorys = new Vector<>();
|
this.filterFactorys = new Vector<>();
|
||||||
Thread worker = new Thread(this);
|
Thread worker = new Thread(this);
|
||||||
worker.setDaemon(true);
|
worker.setDaemon(true);
|
||||||
@ -29,7 +29,7 @@ public class UpdateKeeper implements Runnable {
|
|||||||
* 静态内部类,实现线程安全单例模式
|
* 静态内部类,实现线程安全单例模式
|
||||||
*/
|
*/
|
||||||
private static class Builder {
|
private static class Builder {
|
||||||
private static UpdateKeeper singleton = new UpdateKeeper();
|
private static UpdateThread singleton = new UpdateThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,8 +38,8 @@ public class UpdateKeeper implements Runnable {
|
|||||||
*
|
*
|
||||||
* @return 本类的实例
|
* @return 本类的实例
|
||||||
*/
|
*/
|
||||||
static UpdateKeeper getInstance() {
|
static UpdateThread getInstance() {
|
||||||
return UpdateKeeper.Builder.singleton;
|
return UpdateThread.Builder.singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
Loading…
x
Reference in New Issue
Block a user