2017-05-23 70 views
0

我正在使用MarkLogic Java客戶端加載大量數據。一段時間後,我收到以下錯誤,然後重複。MarkLogic 9 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)); 

我如何才能避免這個錯誤?

回答

2

我沒有看到你在代碼示例中做錯了什麼。我猜你分享的堆棧跟蹤來自一些不同的代碼。您通常不希望在像HarvestJDBCDataServlet.doPost這樣的方法內創建新的DatabaseClient,因爲您希望DatabaseClient實例在Web應用程序的生命週期中共享,因爲它包含共享連接池。如果您在調用dmm.stopJob(batcher)之後調用batcher.add,您將看到的錯誤的唯一方法是。這是日誌中唯一的錯誤還是另一個錯誤先於此?無論如何,如果您認爲您遇到了錯誤,請在github中提出問題。

+0

這是否意味着DataMovementManager不是線程安全的? –

+0

否。相反,DataMovementManage和WriteBatcher被設計爲線程安全的。但是,您需要協調您的線程,因此在完成batcher.add的調用之後,您只需調用dmm.stopJob。 –