运行 多台机器上的调度程序
Running a scheduler on more than one machine
我有一个 Java 服务,它在未来每 y 秒创建 x 个游戏(计算每个游戏的开始时间和结束时间)并将它们插入 DB2 table。该代码主要查找上次创建的游戏的结束时间(如果存在且不在过去),并使用它来创建未来的游戏。否则,它使用游戏持续时间(所有游戏都相同)和当前时间来创建新游戏。
此服务会运行同时在多台机器上进行,因此存在最后一场比赛的检查不准确的风险。一种解决方案是锁定整个 table,但这不能很好地扩展。有什么更有效处理这种情况的想法吗?
DB2(和大多数企业数据库供应商)为高并发工作负载提供了适当的锁定机制以满足数据库 ACID 属性。您不必担心自己对表进行显式锁定。
在 DB2 中,隔离级别决定了数据在被访问时如何锁定或与其他进程隔离。以下是有关不同隔离级别的详细信息:
UR: Allows an application to access uncommitted changes of other transactions.
CS: Locks any row accessed by a transaction of an application while the cursor is positioned on the row. This lock remains in effect until the next row is fetched or the transaction is terminated.
RS: Locks only those rows that an application retrieves within a unit of work. It ensures that any qualifying row read during a unit of work is not changed by other application processes until the unit of work completes.
RR: Locks all the rows an application references within a unit of work.
您可以在本文中详细了解每个隔离级别的限制,以便为您的查询选择最合适的级别:
http://www.ibm.com/developerworks/data/library/techarticle/dm-1107db2isolationlevel/
我有一个 Java 服务,它在未来每 y 秒创建 x 个游戏(计算每个游戏的开始时间和结束时间)并将它们插入 DB2 table。该代码主要查找上次创建的游戏的结束时间(如果存在且不在过去),并使用它来创建未来的游戏。否则,它使用游戏持续时间(所有游戏都相同)和当前时间来创建新游戏。
此服务会运行同时在多台机器上进行,因此存在最后一场比赛的检查不准确的风险。一种解决方案是锁定整个 table,但这不能很好地扩展。有什么更有效处理这种情况的想法吗?
DB2(和大多数企业数据库供应商)为高并发工作负载提供了适当的锁定机制以满足数据库 ACID 属性。您不必担心自己对表进行显式锁定。
在 DB2 中,隔离级别决定了数据在被访问时如何锁定或与其他进程隔离。以下是有关不同隔离级别的详细信息:
UR: Allows an application to access uncommitted changes of other transactions.
CS: Locks any row accessed by a transaction of an application while the cursor is positioned on the row. This lock remains in effect until the next row is fetched or the transaction is terminated.
RS: Locks only those rows that an application retrieves within a unit of work. It ensures that any qualifying row read during a unit of work is not changed by other application processes until the unit of work completes.
RR: Locks all the rows an application references within a unit of work.
您可以在本文中详细了解每个隔离级别的限制,以便为您的查询选择最合适的级别:
http://www.ibm.com/developerworks/data/library/techarticle/dm-1107db2isolationlevel/