私はスレッド プール エグゼキュータを機能させようとしていますが、次のコードでどこかで間違っているのではないかと思っています。
public class testPool implements Runnable {
static Executor pooledExecutor = null;
private Threat thread = null;
private testPool(int minThreadPoolSize,
int initThreadPoolSize,
int maxThreadPoolSize,
int threadKeepAliveTime,
int queueCapacity) throws Exception {
pooledExecutor = new ThreadPoolExecutor(initThreadPoolSize,
maxThreadPoolSize,
(long) (1000 * threadKeepAliveTime),
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(queueCapacity));
this.thread = new Thread(this);
this.thread.setName("testThread");
try {
this.thread.setDaemon(true);
} catch (Exception e) {
// DO Something
}
}
public void run() {
while(true){
try {
// code to get a testobject
pooledExecutor.execute(testObject);
} catch (Exception e) {
//Do something
} finally {
//if shutdown parameter is true
break
}
}
}
}
基本的に、この実装が実際にスレッドを作成するかどうかはわかりませんか? または、スレッドファクトリーを使用する必要がありますか? 以前は createThreads() メソッドを持つ pooledexecutor を使用していましたが、このようなものは表示されません。
また、誰かが最小スレッドプールサイズを設定したい理由はありますか
ヘルプ/アドバイスをいただければ幸いです。