我将运行在GlassFish服务器上的JavaEE JSF应用程序从使用托管Bean迁移到使用CDI。
一切正常,除了使用现在返回
的Neo4j的页面外,所有页面都正确显示org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out
我将问题追溯到特定的git提交,我将类LibraryController更改为:
@ManagedBean
@SessionScoped
public class LibraryController
{
private GraphStorage graphStorage;
public LibraryController()
{
graphStorage = new GraphStorage();
graphStorage.setUp();
}
}
到
@Named
@SessionScoped
public class LibraryController
{
private GraphStorage graphStorage;
public LibraryController()
{
graphStorage = new GraphStorage();
graphStorage.setUp();
}
}
在graphStorage的setUp()方法中使用tx.finish提交neo4j更改时发生超时错误:
public class GraphStorage
{
private void createNodespace()
{
Transaction tx = graphDb.beginTx();
try
{
Node rootNode = graphDb.createNode();
setGraphRootUUIDString(java.util.UUID.randomUUID().toString());
rootNode.setProperty("uuid", getGraphRootUUIDString());
index.add(rootNode, "uuid", rootNode.getProperty("uuid"));
tx.success();
}
finally
{
tx.finish();
}
}
public void setUp()
{
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(FILESYSTEM_DB);
indexManager = graphDb.index();
index = indexManager.forNodes("indexNodes");
registerShutdownHook();
createNodespace();
}
}
注意我在GraphStorage中有一个main方法,它调用相同的setUp()并创建运行正常的相同节点,似乎CDI以某种方式打破了Neo4j的工作方式。 有什么暗示如何解决这个问题吗?
修改 好吧发现GraphStorage中的main方法正确工作,因为它调用构造函数一次,而JavaEE CDI多次调用GraphStorage的构造函数 显然是由于CDI是如何实现的(即代理)。仍然不知道如何解决这个问题
跟踪日志:
Schwerwiegend: Error Rendering View[documents.xhtml]
javax.el.ELException: documents.xhtml @47,61 value="#{libraryController.root}": org.neo4j.graphdb.TransactionFailureException: Unable to commit transaction
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at org.primefaces.component.api.UITree.getValue(UITree.java:118)
at org.primefaces.component.tree.TreeRenderer.encodeMarkup(TreeRenderer.java:228)
at org.primefaces.component.tree.TreeRenderer.encodeEnd(TreeRenderer.java:185)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:70)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:57)
at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:204)
at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:121)
at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:58)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at com.example.common.utils.AuthenticationFilter.doFilter(AuthenticationFilter.java:59)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:744)
Caused by: javax.el.ELException: org.neo4j.graphdb.TransactionFailureException: Unable to commit transaction
at javax.el.BeanELResolver.getValue(BeanELResolver.java:368)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:140)
at com.sun.el.parser.AstValue.getValue(AstValue.java:204)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 59 more
Caused by: org.neo4j.graphdb.TransactionFailureException: Unable to commit transaction
at org.neo4j.kernel.TopLevelTransaction.finish(TopLevelTransaction.java:143)
at com.example.dms.GraphStorage.createNodespace(GraphStorage.java:190)
at com.example.dms.GraphStorage.setUp(GraphStorage.java:405)
at com.example.controllers.LibraryController.<init>(LibraryController.java:94)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:79)
at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:63)
at org.jboss.weld.injection.producer.AbstractInstantiator.newInstance(AbstractInstantiator.java:29)
at org.jboss.weld.injection.producer.DefaultInstantiator.newInstance(DefaultInstantiator.java:90)
at org.jboss.weld.injection.producer.BasicInjectionTarget.produce(BasicInjectionTarget.java:86)
at org.jboss.weld.injection.producer.BeanInjectionTarget.produce(BeanInjectionTarget.java:172)
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:157)
at org.jboss.weld.context.ForwardingContextual.create(ForwardingContextual.java:27)
at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
at org.jboss.weld.context.PassivatingContextWrapper$AbstractPassivatingContextWrapper.get(PassivatingContextWrapper.java:64)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:93)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
at com.example.controllers.LibraryController$Proxy$_$$_WeldClientProxy.getRoot(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
... 66 more
Caused by: org.neo4j.graphdb.TransactionFailureException: commit threw exception
at org.neo4j.kernel.impl.transaction.TxManager.commit(TxManager.java:432)
at org.neo4j.kernel.impl.transaction.TxManager.commit(TxManager.java:344)
at org.neo4j.kernel.impl.transaction.TransactionImpl.commit(TransactionImpl.java:134)
at org.neo4j.kernel.TopLevelTransaction.finish(TopLevelTransaction.java:127)
... 91 more
Caused by: javax.transaction.xa.XAException
at org.neo4j.kernel.impl.transaction.TransactionImpl.doCommit(TransactionImpl.java:576)
at org.neo4j.kernel.impl.transaction.TxManager.commit(TxManager.java:394)
... 94 more
Caused by: java.lang.RuntimeException: org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@/home/antonio.test/glassfish-4.0/glassfish/domains/domain1/config/target/dms-db/index/lucene/node/indexNodes/write.lock
at org.neo4j.index.impl.lucene.LuceneDataSource.newIndexWriter(LuceneDataSource.java:718)
at org.neo4j.index.impl.lucene.LuceneDataSource.syncGetIndexSearcher(LuceneDataSource.java:596)
at org.neo4j.index.impl.lucene.LuceneDataSource.getIndexSearcher(LuceneDataSource.java:560)
at org.neo4j.index.impl.lucene.CommitContext.ensureWriterInstantiated(CommitContext.java:58)
at org.neo4j.index.impl.lucene.LuceneCommand$AddCommand.perform(LuceneCommand.java:188)
at org.neo4j.index.impl.lucene.LuceneTransaction.doCommit(LuceneTransaction.java:286)
at org.neo4j.kernel.impl.transaction.xaframework.XaTransaction.commit(XaTransaction.java:322)
at org.neo4j.kernel.impl.transaction.xaframework.XaResourceManager.commit(XaResourceManager.java:489)
at org.neo4j.kernel.impl.transaction.xaframework.XaResourceHelpImpl.commit(XaResourceHelpImpl.java:64)
at org.neo4j.kernel.impl.transaction.TransactionImpl.doCommit(TransactionImpl.java:570)
... 95 more
Caused by: org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@/home/antonio.test/glassfish-4.0/glassfish/domains/domain1/config/target/dms-db/index/lucene/node/indexNodes/write.lock
at org.apache.lucene.store.Lock.obtain(Lock.java:84)
at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:1098)
at org.neo4j.index.impl.lucene.LuceneDataSource.newIndexWriter(LuceneDataSource.java:707)
... 104 more
答案 0 :(得分:0)
Beans在您发现的情况下调用了两次是正常行为,第一个创建是Weld容器创建bean的作用域代理,以便扩展您的bean的范围代理在其他组件需要您的bean时被注入。 / p>
现在对于解决方案,您应该避免将逻辑放在构造函数中,而是将其放在PostConstructor中,其行为与您期望的一样,因此您可以将代码更改为:
@PostConstruct
void postConstruct()
{
graphStorage = new GraphStorage();
graphStorage.setUp();
}