小弟初开始学习java的lunece做全文索引
在 public synchronized static void runJob() throws Exception{
Map envList = new HashMap();
IEnv env = null;
try {
while (jobList.size() > 0) {
IJob job = ( (IJob) jobList.get(0));
env = (IEnv) envList.get(job.getClass());
if (env == null) {
env = EnvFactory.createEnv(job);
envList.put(job.getClass(), env);
env.initEnv();
}
job.run(env);
//
jobList.remove(job);
}
}
catch (Exception ex) {
throw ex;
}finally{
Iterator it = envList.values().iterator();
while (it.hasNext()) {
( (IEnv) it.next()).release();
}
}
}调用,
public void release() {
System.out.println("pp path="+path);
try {
try {
writer.optimize();
}
catch (CorruptIndexException ex2) {
}
catch (IOException ex2) {
}
writer.close();
// System.out.println("index over");
}
catch (CorruptIndexException ex) {
}
catch (IOException ex) {
}
try {
LuceneUtils.SearcherReload(path);
}
catch (Exception ex1) {
}
}
当然writer在前面有初始化
IndexWriter writer = null;
private static Analyzer analyzer = new IK_CAnalyzer();
String path = null;
public PowerProcessIndexEnv() {
path = getClass().getClassLoader().getResource("").
getFile() + "../lucene_index/pp"; } public PowerProcessIndexEnv(IJob job) {
this.create =((IndexPowerProcessJob) job).isNewCreate();
path = getClass().getClassLoader().getResource("").
getFile() + "../lucene_index/pp";
}
public void initEnv() throws Exception {
//初始化IndexWriter
try {
writer = new IndexWriter(path, analyzer, this.create);
}
catch (java.io.FileNotFoundException ex) {
writer = new IndexWriter(path, analyzer, true);
}
writer.setMergeFactor(1000);
writer.setUseCompoundFile(false);
this.put("writer",writer);
//
}
开始如果在路径里面没有索引文件的时候,执行是不报错的。但如果有了索引文件以后,再次执行就报
java.lang.NullPointerException
at com.beyondbit.lucene.index.support.env.PowerProcessIndexEnv.release(PowerProcessIndexEnv.java:90)
at com.beyondbit.lucene.index.LuceneControl.runJob(LuceneControl.java:105)
at com.beyondbit.lucene.index.LuceneControl$1.run(LuceneControl.java:68)
at java.lang.Thread.run(Thread.java:534)
ERROR 03-19 16:11:37 [Thread-37] (LuceneControl.java:72) - java.lang.NullPointerException
哪位高手能指点下迷津????
在线等。。
在 public synchronized static void runJob() throws Exception{
Map envList = new HashMap();
IEnv env = null;
try {
while (jobList.size() > 0) {
IJob job = ( (IJob) jobList.get(0));
env = (IEnv) envList.get(job.getClass());
if (env == null) {
env = EnvFactory.createEnv(job);
envList.put(job.getClass(), env);
env.initEnv();
}
job.run(env);
//
jobList.remove(job);
}
}
catch (Exception ex) {
throw ex;
}finally{
Iterator it = envList.values().iterator();
while (it.hasNext()) {
( (IEnv) it.next()).release();
}
}
}调用,
public void release() {
System.out.println("pp path="+path);
try {
try {
writer.optimize();
}
catch (CorruptIndexException ex2) {
}
catch (IOException ex2) {
}
writer.close();
// System.out.println("index over");
}
catch (CorruptIndexException ex) {
}
catch (IOException ex) {
}
try {
LuceneUtils.SearcherReload(path);
}
catch (Exception ex1) {
}
}
当然writer在前面有初始化
IndexWriter writer = null;
private static Analyzer analyzer = new IK_CAnalyzer();
String path = null;
public PowerProcessIndexEnv() {
path = getClass().getClassLoader().getResource("").
getFile() + "../lucene_index/pp"; } public PowerProcessIndexEnv(IJob job) {
this.create =((IndexPowerProcessJob) job).isNewCreate();
path = getClass().getClassLoader().getResource("").
getFile() + "../lucene_index/pp";
}
public void initEnv() throws Exception {
//初始化IndexWriter
try {
writer = new IndexWriter(path, analyzer, this.create);
}
catch (java.io.FileNotFoundException ex) {
writer = new IndexWriter(path, analyzer, true);
}
writer.setMergeFactor(1000);
writer.setUseCompoundFile(false);
this.put("writer",writer);
//
}
开始如果在路径里面没有索引文件的时候,执行是不报错的。但如果有了索引文件以后,再次执行就报
java.lang.NullPointerException
at com.beyondbit.lucene.index.support.env.PowerProcessIndexEnv.release(PowerProcessIndexEnv.java:90)
at com.beyondbit.lucene.index.LuceneControl.runJob(LuceneControl.java:105)
at com.beyondbit.lucene.index.LuceneControl$1.run(LuceneControl.java:68)
at java.lang.Thread.run(Thread.java:534)
ERROR 03-19 16:11:37 [Thread-37] (LuceneControl.java:72) - java.lang.NullPointerException
哪位高手能指点下迷津????
在线等。。
解决方案 »
- 利用JNA,java调用c的dll动态连库异常。。。
- SQL语句中,使用where 条件 in (字段)的问题
- 走过路过不要错过!
- 文件输出!
- Hibernate operation: Cannot open connection错误求助
- 在windows下java 开发的web项目是不是放到linux 就一点问题没有了
- 高人,请指教哈!
- 让前台提交的表单给action处理后不跳转
- 小妹妹急求大哥给个答案,做出要我干啥都行.
- 我在用j2ee1.4的deploytool部署其中example程序ConverterApp的时候出现这样的错误,是怎么回事?
- 求助Java高手! 补全classpath之外路径的问题
- 本机部署在was上的项目跳转到tomcat后,session丢失
就是release()方法中的writer.optimize(); 跟踪以后writer为null,但具体问题出现在哪里就弄不太清楚了。
谁能给点意见啊。。