我正在使用 ThreadPoolExecutor 实用程序并通过被调用类中的构造函数传递值。构造函数有两个参数 (1) 一个映射 (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;
}
谢谢 Gendaful