0

我正在使用“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)
4

1 回答 1

1

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

  1. 数据库 URL 不正确
  2. 数据库的端口号已更改,此处类似问题,请参阅讨论中的最后一条评论
  3. 您打开了太多会话,您的数据库无法为您提供新会话。

编辑根据更新的堆栈跟踪

指南针给你两件事:

  1. IndexInput 和 2. IndexOutput

默认情况下 IndexOutput 设置为RAMAndFileJDBCIndexOutput,在一定限制后切换到FileJdbcIndexOutput并创建您的临时文件。

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

于 2013-01-17T03:41:29.263 回答