![]() So the second rule is bound to be relevant as well. Merely living up to the first rule will help, but is hardly practical in realistic applications. Alternatively (if you must): make sure each call stack locks objects in the same predefined order.Within a synchronized block of code, never call another synchronized block (directly or indirectly).In general, deadlocks will not happen (are impossible) if the following techniques are used throughout the code : There are some guidelines that, if enforced consistently, can avoid deadlocks. But the locks they are waiting for are held by another waiting thread, so these locks are never freed. This will lead to an endless wait case, since each thread can only complete when it gets the lock its waiting for. Thread threadB wants to call a synchronized method on objectA.Thread threadA wants to call a synchronized method on objectB.At least one other thread, say threadB, holds a lock on another object, say objectB.One thread, say threadA, holds a lock on some object called objectA (i.e., is in a synchronized block of code).In particular, deadlock can happen if all of the following hold: In Java, deadlocks are most commonly caused by synchronized blocks of code. The thread that starts and stops the transaction service (usually the main thread of the application). If you have any log administrators then these will inspect the coordinator(s) in a GUI-spawned thread. In the case of recursive calls between virtual machines, this will even lead to re-entrant commits (the parent coordinator is in turn a subordinate of its own subordinates). Imported transactions will have a subordinate coordinator in the transaction service, and this subordinate coordinator will be called by the commit threads of the remote parent transaction. Two-phase termination is done by a separate thread (unless you explicitly disable this). The thread responsible for triggering rollback due to timeout. ![]() The thread that starts the transaction, does work within its scope and then terminates the transaction. ![]() Each transaction coordinator has a number of threads that act on it: Thread ![]()
0 Comments
Leave a Reply. |