私はSpringのバッチジョブを分割ステップで構成し、分割ステップはチャンクで処理しています。SpringバッチのWriterからRunnableを起動しました。分割されたステップ
さらに、新しいスレッド(Runnable
の実装)をメソッドpublic void write(List<? extends VO> itemsToWrite)
から起動できますか?
は基本的に、作家は、ここでのLuceneを使用してインデックスを書き込み、書き込みがList
chunk-size
の項目を有しているので、私はList
そのセグメントに分割し、新しいRunnable
に各セグメントを通過すると考え。
これは良いアプローチですか?
私はサンプルをコーディングしましたが、ほとんどの場合は動作しますが、何度か立ち往生してしまいます。
私が心配する必要があることはありますか?またはこれを達成するために春のバッチに何かが組み込まれていますか?
チャンク全体に対して1つのスレッドで書き込みを行うことは望ましくありません。私はさらにチャンクを分割したいと思う。
のLucene IndexWriter
は、スレッドセーフであるとアプローチはhere
サンプルコードをリストされている - ライターは、私は、スレッドプールからスレッドを開いている項目のList
を取得しますか?私は、チャンクのために終了するプール、
@Override
public void write(List<? extends IndexerInputVO> inputItems) throws Exception {
int docsPerThread = Constants.NUMBER_OF_DOCS_PER_INDEX_WRITER_THREADS;
int docSize = inputItems.size();
int remainder = docSize%docsPerThread;
int poolSize = docSize/docsPerThread;
ExecutorService executor = Executors.newFixedThreadPool(poolSize+1);
int fromIndex=0;
int toIndex = docsPerThread;
if(docSize < docsPerThread){
executor.submit(new IndexWriterRunnable(this.luceneObjects,service,inputItems));
}else{
for(int i=1;i<=poolSize;i++){
executor.submit(new IndexWriterRunnable(this.luceneObjects,service,inputItems.subList(fromIndex, toIndex)));
fromIndex+=docsPerThread;
toIndex+=docsPerThread;
}
if(remainder != 0){
toIndex=docSize;
executor.submit(new IndexWriterRunnable(this.luceneObjects,service,inputItems.subList(fromIndex, toIndex)));
}
}
executor.shutdown();
while(executor.isTerminated()){
;
}