3

我正在为 web 控制长期运行的过程进行概念验证。为了模拟,我创建了一个计数器来每 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。

谢谢

4

0 回答 0