Synchronized static singleton ThreadPool Executor を定義済みのプロパティで初期化したいと考えています。
アプリケーション全体で利用できるようにしたいので、サーバーの再起動または停止時に破棄する必要があります。
public class ThreadPoolExecutor extends java.util.concurrent.ThreadPoolExecutor {
private static Properties properties;
static {
try {
properties.load(ThreadPoolExecutor .class.getClassLoader().getResourceAsStream("config.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}
static final int defaultCorePoolSize = Integer.valueOf((String) properties.get("CORE_POOL_SIZE"));
static final int defaultMaximumPoolSize = Integer.valueOf((String) properties.get("MAX_POOL_SIZE"));
static final long defaultKeepAliveTime = Integer.valueOf((String) properties.get("KEEP_ALIVE_TIME"));
static final TimeUnit defaultTimeUnit = TimeUnit.MINUTES;
static final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>();
private static ThreadPoolExecutor instance;
private ThreadPoolExecutor() {
super(defaultCorePoolSize, defaultMaximumPoolSize, defaultKeepAliveTime, defaultTimeUnit, workQueue);
}
synchronized static ThreadPoolExecutor getInstance() {
if (instance == null) {
instance = new ThreadPoolExecutor();
}
return instance;
}
これは私が今までやってきたことです(私はマルチスレッドの初心者です)。
私のアプリケーションは完全にマルチスレッドに基づいているため、要件とここで改善すべきことをどのように達成するのですか? 私が言ったように、アプリケーション全体でそれを維持/利用できるようにするにはどうすればよいですか。