Java synchronized method

First of all, forget about synchronized methods. A so-called synchronized method… synchronized AnyType foobar(…) { doSomething(); } Is nothing but a shortcut way of writing this: AnyType foobar(…) { synchronized(this) { doSomething(); } } There is nothing special about the method in either case. What is special is the synchronized block, and what a synchronized … Read more

Transaction (Process ID) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction

This occurs when two Sql Server processes are accessing the same resources, but in a different order. Therefore they end up both waiting for the other process, which is a deadlock. There are a number of ways to prevent it, including: Avoid taking unneccessary locks. Review the transaction isolation level required for the query, use … Read more

Tips to prevent deadlocks in java

Some quick tips out of my head don’t use multiple threads (like Swing does, for example, by mandating that everything is done in the EDT) don’t hold several locks at once. If you do, always acquire the locks in the same order don’t execute foreign code while holding a lock use interruptible locks

How to simulate DEADLOCK on SQL Server?

You can create a deadlock by using the steps shown below. First, create the global temp tables with sample data. –Two global temp tables with sample data for demo purposes. CREATE TABLE ##Employees ( EmpId INT IDENTITY, EmpName VARCHAR(16), Phone VARCHAR(16) ) GO INSERT INTO ##Employees (EmpName, Phone) VALUES (‘Martha’, ‘800-555-1212’), (‘Jimmy’, ‘619-555-8080’) GO CREATE … Read more

What is the difference between “wait-die” and “wound-wait” deadlock prevention algorithms?

Wait-Die scheme It is a non-preemptive technique for deadlock prevention. When transaction Tn requests a data item currently held by Tk, Tn is allowed to wait only if it has a timestamp smaller than that of Tk (That is Tn is older than Tk), otherwise Tn is killed (“die”). In this scheme, if a transaction … Read more

ReentrantReadWriteLock: what’s the difference between ReadLock and WriteLock?

readLock.lock(); This means that if any other thread is writing (i.e. holds a write lock) then stop here until no other thread is writing. Once the lock is granted no other thread will be allowed to write (i.e. take a write lock) until the lock is released. writeLock.lock(); This means that if any other thread … Read more

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