在多台计算机上运行调度程序



我有一个Java服务,将来每y秒(计算每个Y的开始时间和结束时间)将来创建X Games,并将它们插入DB2表中。该代码基本上是在上一个创建的游戏的结束时间(如果存在的话)的结束时间,并且不在过去,并使用它来创建未来的游戏。否则,它使用游戏持续时间(所有游戏中的相同)和创建新游戏的当前时间。

此服务将立即在几台计算机上运行,因此有可能对最后一款游戏进行检查的风险不准确。一种解决方案是锁定整个桌子,但这并不能很好地扩展。关于更有效处理这种情况的任何想法?

db2(以及大多数企业数据库供应商)具有适当的锁定机制,以实现高度并发工作负载,以满足数据库酸属性。您不必担心自己将明确的锁放在桌子上。

在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/developererworks/data/library/techarticle/dm-1107db2isolationlevel/

最新更新