【发布时间】:2016-09-27 06:33:46
【问题描述】:
此问题与my another SO question 有关。
为了让IndexWriter 在分区步骤期间保持打开状态,我想在分区器的ExecutionContext 中添加IndexWriter,然后在StepExecutionListenerSupport 的afterStep(StepExecution stepExecution) 方法中关闭。
我在这种方法中面临的挑战是ExecutionContext 需要对象可序列化。
鉴于这两个问题,Q1,Q2 - 这似乎不可行,因为我无法在我的自定义编写器中添加 no - arg 构造函数,因为 IndexWriter 没有任何 no - arg 构造函数。
public class CustomIndexWriter extends IndexWriter implements Serializable {
/*
private Directory d;
private IndexWriterConfig conf;
public CustomIndexWriter(){
super();
super(this.d, this.conf);
}
*/
public CustomIndexWriter(Directory d, IndexWriterConfig conf) throws IOException {
super(d, conf);
}
/**
*
*/
private static final long serialVersionUID = 1L;
private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException{
input.defaultReadObject();
}
private void writeObject(ObjectOutputStream output) throws IOException, ClassNotFoundException {
output.defaultWriteObject();
}
}
在上面的代码中,我无法添加显示为注释的构造函数,因为在 Super 类中不存在 no - arg 构造函数并且无法访问 this 之前的字段 super 。
有没有办法做到这一点?
【问题讨论】:
标签: java serialization lucene spring-batch