Websphere, SQL Server and Deadlock

How avoid deadlock with Websphere and SQL Server

When you create a datasource in Websphere for a SQL Server database, the default isolation level is Repeatable Read. At first it seems the best choice, but repeatable read as isolation level means the presence of table lock, and with table lock, a deadlock can happen at any time!

For example, considere this application stack:

Java 8
Spring Boot 2.4.1
Websphere 8.5.5
SQL Server 2008

If you need a transaction with REQUIRES_NEW propagation, a deadlock can happen if you are going to update the same tables in the parent and child transaction. This because the isolation level is Repeatable Read.

The solution is to relax the isolation level to Read Committed. You avoid deadlock and with hibernate optimistic lock, there is no possibility to miss information.

To set the isolation level of a datasource in Websphere, you have to navigate the path:

Data sources > [datasource name] > Custom properties

and set

webSphereDefaultIsolationLevel=2

where 2 means Read Committed.

That’s what you need to avoid deadlock!

And remember, if you need a pessimistic lock, with JPA is simple to set table lock for a single query (see for example my previous post about it).

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: