gpt4 book ai didi

spring-webflow - Spring Web Flow LockTimeoutException

转载 作者:行者123 更新时间:2023-12-03 20:25:57 26 4
gpt4 key购买 nike

我们在 Weblogic 10 集群环境中使用 Spring Web Flow (2.0.9)。在生产中,我们得到了很多 LockTimeoutException : 30 秒后无法获取对话锁定。

我一直在试图弄清楚为什么在某些情况下只有一次单击或我们正在访问网站本身的主页时会出现上述异常。

请在 SWF 中找到试图锁定 FlowController 的代码。我想不通的是锁是在正在访问的 servlet 上还是其他什么?

请帮助了解在 Web 应用程序中发生此锁定时,SWF 中实际锁定的是哪个资源?

要了解 ReentrantLock 的概念,请引用下面的链接。

What is the Re-entrant lock and concept in general?

提前致谢。

异常堆栈跟踪

org.springframework.webflow.conversation.impl.LockTimeoutException: Unable to acquire conversation lock after 30 seconds
at org.springframework.webflow.conversation.impl.JdkConcurrentConversationLock.lock(JdkConcurrentConversationLock.java:44)
at org.springframework.webflow.conversation.impl.ContainedConversation.lock(ContainedConversation.java:69)
at org.springframework.webflow.execution.repository.support.ConversationBackedFlowExecutionLock.lock(ConversationBackedFlowExecutionLock.java:51)
at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:166)
at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183)
at org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:174)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)

SWF 中的锁实现
package org.springframework.webflow.conversation.impl;

import java.io.Serializable;
import java.util.concurrent.locks.ReentrantLock;

/**
* A conversation lock that relies on a {@link ReentrantLock} within Java 5's <code>util.concurrent.locks</code>
* package.
*
* @author Keith Donald
*/
class JdkConcurrentConversationLock implements ConversationLock, Serializable {

/**
* The lock.
*/
private ReentrantLock lock = new ReentrantLock();

public void lock() {
// ensure non-reentrant behaviour
if (!lock.isHeldByCurrentThread()) {
lock.lock();
}
}

public void unlock() {
// ensure non-reentrant behaviour
if (lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
}

最佳答案

Spring Webflow 作为状态机运行,在可能具有关联 View 的不同状态之间执行转换。多个同时执行的转换没有意义,因此 SWF 使用锁定系统来确保 每个流执行(或 session )一次仅处理一个 HTTP 请求 .

不要太在意 ReentrantLock 的概念,它只是防止同一个线程等待它已经持有的锁。

在回答您的问题时,只有在请求处理期间被 Spring Webflow 锁定的流执行(特定对话实例)。服务器仍然会处理来自其他用户的请求,甚至是来自同一用户对不同流程执行的请求。

LockTimeoutException 很难解决,因为根本问题不是抛出异常的线程。 LockTimeoutException 发生是因为另一个较早的请求花费的时间超过 30 秒,因此最好找出较早的请求花费这么长时间的原因。

故障排除思路:

  • 实现一个 FlowExecutionListener 来测量每个请求需要多长时间,并记录长请求以及 flowId、stateId 和转换事件,这将允许您处理长时间运行的请求。
  • 避免 LockTimeoutException 本身的一种好方法是在单击按钮/链接后使用 javascript 禁用提交按钮和链接。显然这并不能解决初始 30 秒+请求的问题。

  • 您可以增加 LockTimeoutException 的超时时间,但这并不能解决实际问题并导致更糟糕的用户体验。 30 秒的请求是问题所在。

    最后,你提到:

    I have been trying to figure out why does above exception comes in some cases when there is only a single click or we are accessing the home page of the site itself.



    我建议您尝试在浏览器的开发人员工具窗口打开的情况下重新创建问题,观察“网络”选项卡,也许有一个 AJAX 请求在后台运行并持有锁。

    关于spring-webflow - Spring Web Flow LockTimeoutException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9533786/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com