使用批处理器的MarkLogic 9 Java客户端出错

时间:2017-05-23 19:24:59

标签: java marklogic marklogic-9

我正在使用MarkLogic Java客户端加载大量数据。一段时间后我收到以下错误,然后它重复。

    23-May-2017 15:09:11.199 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [easymetahub] appears to have started a thread named [pool-20-thread-12] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
 java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1066)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 java.lang.Thread.run(Thread.java:745)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:105)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1078)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:760)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1524)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
java.lang.IllegalStateException: This instance has been stopped
    at com.marklogic.client.datamovement.impl.WriteBatcherImpl.requireNotStopped(WriteBatcherImpl.java:347)
    at com.marklogic.client.datamovement.impl.WriteBatcherImpl.add(WriteBatcherImpl.java:283)
    at com.marklogic.client.datamovement.impl.WriteBatcherImpl.add(WriteBatcherImpl.java:267)
    at com.easymetahub.HarvestJDBCData.doRoot(HarvestJDBCData.java:486)
    at com.easymetahub.HarvestJDBCData.doSomething(HarvestJDBCData.java:243)
    at com.easymetahub.HarvestJDBCData.processBatchSegment(HarvestJDBCData.java:146)
    at com.easymetahub.HarvestJDBCDataServlet.doPost(HarvestJDBCDataServlet.java:33)
    at com.easymetahub.HarvestJDBCDataServlet.doGet(HarvestJDBCDataServlet.java:45)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:232)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:105)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1078)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:760)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1524)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
java.lang.IllegalStateException: This instance has been stopped
    at com.marklogic.client.datamovement.impl.WriteBatcherImpl.requireNotStopped(WriteBatcherImpl.java:347)
    at com.marklogic.client.datamovement.impl.WriteBatcherImpl.add(WriteBatcherImpl.java:283)
    at com.marklogic.client.datamovement.impl.WriteBatcherImpl.add(WriteBatcherImpl.java:267)
    at com.easymetahub.HarvestJDBCData.doRoot(HarvestJDBCData.java:486)
    at com.easymetahub.HarvestJDBCData.doSomething(HarvestJDBCData.java:243)
    at com.easymetahub.HarvestJDBCData.processBatchSegment(HarvestJDBCData.java:146)
    at com.easymetahub.HarvestJDBCDataServlet.doPost(HarvestJDBCDataServlet.java:33)
    at com.easymetahub.HarvestJDBCDataServlet.doGet(HarvestJDBCDataServlet.java:45)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:232)

我从示例中复制并修改了以下代码:

        client = DatabaseClientFactory.newClient("localhost", 8000, "emh-entity-manager-content", new DatabaseClientFactory.DigestAuthContext("admin", "mladmin"));
    DataMovementManager dmm = client.newDataMovementManager();
    batcher = dmm.newWriteBatcher();
    batcher.withBatchSize(5000)
            .withThreadCount(30)
            .onBatchSuccess(batch-> {
                System.out.println(
                        batch.getTimestamp().getTime() +
                                " documents written: " +
                                batch.getJobWritesSoFar() +
                                " \t[" + sourceName + "] [" + start + "]");
            })
            .onBatchFailure((batch,throwable) -> {
                System.out.println("Failure on " + sourceName);
                throwable.printStackTrace();
            });

    dmm.startJob(batcher);

    doSomething(harvestNode);
    // Start any partial batches waiting for more input, then wait
    // for all batches to complete. This call will block.
    batcher.flushAndWait();
    dmm.stopJob(batcher);

doSomething调用的地方

                batcher.add(entityPath, getStringFromDocument(outDoc));

如何避免此错误?

1 个答案:

答案 0 :(得分:2)

我在代码示例中没有看到任何错误。我猜你分享的堆栈跟踪来自一些不同的代码。您通常不希望在HarvestJDBCDataServlet.doPost等方法中创建新的DatabaseClient,因为您希望在Web应用程序的生命周期内共享DatabaseClient实例,因为它包含共享连接池。你得到错误的唯一方法就是你在调用dmm.stopJob(batcher)后调用batcher.add。这是日志中唯一的错误还是在此之前发生了其他错误?在任何情况下,如果您认为自己遇到了错误,请在github中提出问题。