【发布时间】:2015-03-22 13:20:15
【问题描述】:
我们有一个 spring mvc Web 应用程序,它将为许多用户的操作提供服务。 我们的数据源是一个 mySQL DB。
Web 应用程序位于 Tomcat 服务器集群上。
用户在与 Web 应用程序交互时没有会话。
该协议是用户和网络应用程序之间的简单 REST API。
如果另一个请求处理仍在进行中,我们希望忽略用户请求。例如:
user1 requests for action1...
action1 handling begins in webapp.
user1 requests for action1 again (before the handling is completed)
server declines the 2nd request since action1 handling is still in progress..
action1 handling completed.
result for action1 is returned to user1's client.
(now further actions is accepted by the web app)
如何实现这一目标?如果我们使用 web 应用程序的单个节点,我们可以简单地在内存中管理它,但由于我们使用集群并且没有共享内存\缓存,它不会工作。
我们考虑的另一种选择是在数据库中使用锁定, 例如,在专用表(称为 userLock)中为用户 ID 创建一个约束,在每次处理之前,我们只需将其插入到该表中,并通过从中删除条目来完成,现在如果发出非法请求,则会引发约束异常并未处理)
这种“信号量”行为还有其他替代方法吗?
【问题讨论】:
标签: java mysql spring tomcat concurrency