我正在为网络控制长时间运行过程做出概念验证。为了模拟我创建一个计数器来计算每1秒的数字。我有一个带开始/停止按钮的JSF页面。 当我按下启动时,我可以检查计数器开始计数的日志,但是当我关闭停止时,我遇到了超时异常。
这是Count.xhtml
<f:view
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
<h:form>
<h:commandButton value="Start" action="#{counter.start}" />
<h:commandButton value="End" action="#{counter.end}" />
</h:form>
</body>
</html>
</f:view>
这是CounterFace.java
package nawa.bean;
import javax.ejb.EJB;
import javax.faces.bean.*;
@ManagedBean(name="counter")
@ApplicationScoped
public class CounterFace
{
@EJB
private Counter counter;
public void start()
{
counter.startCounting();
System.out.println(counter.toString());
}
public void stop()
{
counter.endCounting();
System.out.println(counter.toString());
}
}
这是Counter.java
package nawa.bean;
import javax.ejb.*;
/**
* Session Bean implementation class Counter
*/
@Stateful
@LocalBean
public class Counter
{
private int count = 0;
volatile boolean isRunning = false;
@EJB
private Logger logger;
private void count()
{
this.count++;
this.logger.addMessage("Counter(" + this.count + ")");
}
public boolean isRunning()
{
return this.isRunning;
}
@Asynchronous
public void startCounting()
{
this.isRunning = true;
while (this.isRunning)
{
this.count();
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
// TODO: handle exception
}
}
}
@Asynchronous
public void endCounting()
{
this.isRunning = false;
this.logger.addMessage("EndCounting(" + this.count + ")");
}
}
以下是例外:
18:15:55,418 ERROR [org.jboss.as.ejb3] (EJB default - 3) JBAS014102: Asynchronous invocation failed: javax.ejb.ConcurrentAccessTimeoutException: JBAS014360: EJB 3.1 FR 4.3.14.1 concurrent access timeout on org.jboss.invocation.InterceptorContext@3a552b48 - could not obtain lock within 5000 MILLISECONDS
at org.jboss.as.ejb3.component.stateful.StatefulSessionSynchronizationInterceptor.processInvocation(StatefulSessionSynchronizationInterceptor.java:117) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ejb3.component.stateful.StatefulComponentInstanceInterceptor.processInvocation(StatefulComponentInstanceInterceptor.java:66) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
任何人都可以指导我吗?这里发生了什么?我正在使用JBoss 7.1。
由于