Programmatic deadlock detection in java

You can do this programmatically using the ThreadMXBean that ships with the JDK: ThreadMXBean bean = ManagementFactory.getThreadMXBean(); long[] threadIds = bean.findDeadlockedThreads(); // Returns null if no threads are deadlocked. if (threadIds != null) { ThreadInfo[] infos = bean.getThreadInfo(threadIds); for (ThreadInfo info : infos) { StackTraceElement[] stack = info.getStackTrace(); // Log or store stack trace information. … Read more

TransactionScope Prematurely Completed

Don’t forget to supress your select statements from your TransactionScope. In SQL Server 2005 and above, even when you use with(nolock), locks are still created on those tables the select touches. Check this out, it shows you how to setup and use TransactionScope. using(TransactionScope ts = new TransactionScope { // db calls here are in … Read more

Deadlock detection in Java

Since JDK 1.5 there are very useful methods in the java.lang.management package to find and inspect deadlocks that occurs. See the findMonitorDeadlockedThreads() and findDeadlockedThreads() method of the ThreadMXBean class. A possible way to use this is to have a separate watchdog thread (or periodic task) that does this. Sample code: ThreadMXBean tmx = ManagementFactory.getThreadMXBean(); long[] … Read more

Deadlock when accessing StackExchange.Redis

These are the workarounds I’ve found to this deadlock problem: Workaround #1 By default StackExchange.Redis will ensure that commands are completed in the same order that result messages are received. This could cause a deadlock as described in this question. Disable that behavior by setting PreserveAsyncOrder to false. ConnectionMultiplexer connection = …; connection.PreserveAsyncOrder = false; … Read more

How to solve SQL Server Error 1222 i.e Unlock a SQL Server table

In the SQL Server Management Studio, to find out details of the active transaction, execute following command DBCC opentran() You will get the detail of the active transaction, then from the SPID of the active transaction, get the detail about the SPID using following commands exec sp_who2 <SPID> exec sp_lock <SPID> For example, if SPID … Read more

Diagnosing Deadlocks in SQL Server 2005

According to MSDN: http://msdn.microsoft.com/en-us/library/ms191242.aspx When either the READ COMMITTED SNAPSHOT or ALLOW SNAPSHOT ISOLATION database options are ON, logical copies (versions) are maintained for all data modifications performed in the database. Every time a row is modified by a specific transaction, the instance of the Database Engine stores a version of the previously committed image … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)