LoginSignup
2
4

More than 5 years have passed since last update.

S2JDBCのトランザクション分離レベルを変更する

Posted at

トランザクション分離レベルとは

複数のトランザクションで処理する際に、お互いに与える影響にレベルを指定してコントロールすることができます。
英語では Transaction isolation level と言います。
ANSI標準では、下記の 4つの分離レベルが定義されています。

  • READ UNCOMMITTED
  • READ COMMITTED
  • REPEATABLE READ
  • SERIALIZABLE

READ UNCOMMITED がレベルが 1番低く、下に行くほどレベルが高くなります。
レベルが低いと、他のトランザクションの影響を受けやすくなる反面、「待ち」が発生しにくくなるため、バッチ処理などで有利です。逆にレベルが高いと、影響を受けにくくするために、ロックなどによる影響が強くなり、「待ち」が発生しやすくなります。

Seasar の S2JDBCでトランザクション分離レベルを指定する方法

diconファイルの "connectionPool" の定義で指定することが可能です。
デフォルトでは -1 になっていますが、ここに java.sql.Connection の定数を指定します。

diconファイル (サンプル)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN" "http://www.seasar.org/dtd/components24.dtd">
<components>

    :    :    :

  <component name="connectionPool" class="org.seasar.extension.dbcp.impl.ConnectionPoolImpl">
    <property name="transactionIsolationLevel">@java.sql.Connection@TRANSACTION_READ_COMMITTED</property>
    :    :    :
  </component>

    :    :    :

</components>
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4