尝试在for循环内连续向lucene索引添加文档时抛出异常

时间:2013-01-16 11:07:15

标签: mysql lucene wso2 compass-lucene wso2dss

我正在使用“compass-2.2.0”在MySql数据库表中创建lucene索引。 这是我索引文档的代码的一部分,在尝试在for循环内连续向lucene索引添加文档时抛出异常。解决此错误的任何解决方法?

我的托管服务器是WSo2 Stratoes基于tomcat的服务器和Wso2 Stratoes数据服务服务器。我的程序在本地tomcat / mySql服务器上工作。

这是我关注的示例博客帖子 - http://mprabhat.wordpress.com/2012/08/13/create-lucene-index-in-database-using-jdbcdirectory/

 private void addIndex(IndexWriter indexWriter) throws CorruptIndexException, IOException {
        try {
            for (int i = 0; i < docNames.length; i++) {
                StringReader strRdElt = new StringReader(new DefaultTokenizer().processText(filesInText[i]));
                StringReader docId = new StringReader(Integer.toString(i));

                Document doc = new Document();

                doc.add(new Field("doccontent", strRdElt, Field.TermVector.YES));
                doc.add(new Field("docid", docId, Field.TermVector.YES));


                indexWriter.addDocument(doc);

            }
          //  indexWriter.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

这是我遇到的新错误,我正在使用的服务器不允许创建临时文件。在尝试将内容写入数据库时​​,它以某种方式创建临时文件。我在上面的循环中进行了调试,大约5次迭代它成功然后发生以下错误。解决此错误的任何解决方法?

java.lang.SecurityException: Unable to create temporary file
        at java.io.File.checkAndCreate(File.java:1701)
        at java.io.File.createTempFile(File.java:1792)
        at java.io.File.createTempFile(File.java:1828)
        at org.apache.lucene.store.jdbc.index.FileJdbcIndexOutput.configure(File
JdbcIndexOutput.java:46)
        at org.apache.lucene.store.jdbc.index.RAMAndFileJdbcIndexOutput.switchIf
Needed(RAMAndFileJdbcIndexOutput.java:113)
        at org.apache.lucene.store.jdbc.index.RAMAndFileJdbcIndexOutput.writeByt
es(RAMAndFileJdbcIndexOutput.java:73)
        at org.apache.lucene.store.DataOutput.writeBytes(DataOutput.java:43)
        at org.apache.lucene.store.RAMOutputStream.writeTo(RAMOutputStream.java:
65)
        at org.apache.lucene.index.TermVectorsTermsWriter.finishDocument(TermVec
torsTermsWriter.java:170)
        at org.apache.lucene.index.TermVectorsTermsWriter$PerDoc.finish(TermVect
orsTermsWriter.java:258)
        at org.apache.lucene.index.DocumentsWriter$WaitQueue.writeDocument(Docum
entsWriter.java:1404)
        at org.apache.lucene.index.DocumentsWriter$WaitQueue.add(DocumentsWriter
.java:1424)
        at org.apache.lucene.index.DocumentsWriter.finishDocument(DocumentsWrite
r.java:1043)
        at org.apache.lucene.index.DocumentsWriter.updateDocument(DocumentsWrite
r.java:772)
        at org.apache.lucene.index.IndexWriter.addDocument(IndexWriter.java:2060
)
        at org.apache.lucene.index.IndexWriter.addDocument(IndexWriter.java:2034
)
        at org.karsha.base.DocIndexer_test.addIndex(DocIndexer_test.java:168)
        at org.karsha.base.DocIndexer_test.indexToDB(DocIndexer_test.java:115)
        at org.karsha.base.DocIndexer_test.topKFiboTerms(DocIndexer_test.java:35
9)
        at org.karsha.controler.RecommondTermsServelet.doGet(RecommondTermsServe
let.java:379)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at sun.reflect.GeneratedMethodAccessor75.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:274
)
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:271
)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
        at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:3
06)
        at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.
java:166)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:299)
        at org.apache.catalina.core.ApplicationFilterChain.access$000(Applicatio
nFilterChain.java:57)
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilt
erChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilt
erChain.java:189)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:225)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:123)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:168)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:98)
        at org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValv
e.java:172)
        at org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.inv
oke(CarbonStuckThreadDetectionValve.java:156)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
927)
        at org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(Ca
rbonContextCreatorValve.java:52)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:407)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
11Processor.java:1001)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:579)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoin
t.java:1653)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:908)
        at java.lang.Thread.run(Thread.java:619)

1 个答案:

答案 0 :(得分:1)

您可以从数据库中获取ThreadDeath异常的原因有很多。

  1. 数据库网址不正确
  2. 数据库的端口号已更改,类似问题here,请参阅讨论中的最后评论
  3. 您打开的会话太多,而您的数据库无法为您提供新会话。
  4. 编辑根据更新的堆栈跟踪

    指南针为您提供两件事:

    1. IndexInput和2. IndexOutput
    2. 默认情况下,IndexOutput设置为RAMAndFileJDBCIndexOutput,在certain limit切换到FileJdbcIndexOutput后,您的临时文件即被创建。

      要解决此问题,您可以更改此默认值或更改JDBCDirectorySettings中的默认IndexOutput。