【发布时间】:2013-10-07 11:20:59
【问题描述】:
我有一个网站,它有一个方法(在支持 bean 中),它执行几个 READ 请求(例如检查用户的权限),然后插入一些数据。
程序如下所示:
1.) SELECT * FROM userLocks (table which logs the users which are exclusively working on a topic, to avoid redundancy). it checks if there is currently no lock (user working) for the topic.
2.) SELECT * FROM ... (some other selects for further checking)
3.) INSERT INTO userLocks (curUser, timeout) values (...) (if everything was ok, create a new lock for the current user for the topic)
我现在面临的问题是:在第一次选择和插入之间,许多其他用户可以请求操纵表 userLocks 数据的同一网站。它似乎不是线程安全的。
这个问题有解决办法吗?我只需要在此过程中为其他用户锁定所有使用过的表。 (另一个请求应该等到锁被释放,这不会超过半秒......)
(我使用 InnoDB)
【问题讨论】:
-
你关闭了自动提交吗?