私は ThreadPoolExecutor ユーティリティを使用しており、呼び出されたクラスのコンストラクターを介して値を渡しています。コンストラクターは、2 つの引数 (1) マップ (2) 文字列を取ります。
2 つの引数 (マップと文字列) を取る呼び出されたクラスの Bean を宣言する方法について混乱しています。私のコードは以下の通りです。
***Calling Class***
public class Starter {
ProcessScheduler deleteBatch;
public ProcessScheduler getDeleteBatch() {
return deleteBatch;
}
public void setDeleteBatch(ProcessScheduler deleteBatch) {
this.deleteBatch = deleteBatch;
}
public void start() {
ThreadPoolExecutor executor = testThreadPoolExecutorService.createNewThreadPool();
for (int i=0;i<=5;i++)
{
Map m4 = arrayRecords.get(i);
executor.execute(new ProcessScheduler("Thread #"+i,m4)); // Comment - started
The above line executes fine but it gives null pointer error if I will call any other method from the run() inside called class(ProcessScheduler). So I have use a Bean such as executor.execute(getDeleteBatch("Thread #"+i,m4)) to get the instance of the bean. But I dont know how to do this in this case?
// Comment - ended
}
***Called Class***
public class ProcessScheduler implements Runnable {
public ProcessScheduler(String taskName, Map m) {
this.taskName = taskName;
this.deleteRecordsMap = (HashMap) m;
}
Processor processor;
public Processor getProcessor()
{
return processor;
}
public void setProcessor(Processor mappProcessor) {
this.mappProcessor = mappProcessor;
}
public void run()
{
// This returns null
processor.getNumbers();
}
}
I have some confusions as below.
(1) How to declare a bean for ProcessScheduler in this case.
(2) Is the declaration of getDeleteBatch is correct in this case like below?
public ProcessScheduler getDeleteBatch() {
return deleteBatch;
}
ありがとうゲンダフル