8/30/2023 0 Comments Java deadlock detectionfindbugsHere is a sample deadlock that the findDeadlockedThreads method mentioned earlier won't get: import. The thread might even have thrown an exception and died leaving the read count non-zero. What makes it especially hard to debug is that there is no record of who has entered a read lock. A strict rule of courtesy is that when you bow to a friend, you must remain bowed until your friend has a chance to return the bow. Alphonse and Gaston are friends, and great believers in courtesy. That is where you have a ReentrantReadWriteLock and one thread grabs the read lock and then (say) tries to enter a monitor held by some other thread that is also waiting to grab the write lock. Deadlock describes a situation where two or more threads are blocked forever, waiting for each other. Exceptions could prevent releasing too.Note that there is a type of deadlock using the concurrent package that is very hard to debug. A common error could be to lock at the start of a function, unlock at the end, but have a conditional return statement somewhere in between. In your code try to follow the complete logical flow of control between initialising the lock and releasing it. (I found the user interface to be the source of the bug often enough) Remove everything gui related, for example any output about the actual processing state. Maybe even write some small program that takes only some of the classes and runs only the most basic tests (still in several threads of course). This seems to assume a 'deadlock' is when one task wants a resource, that is held by another task. Just a simple line at the beginning of each function and if you can find the right function, split that in smaller chunks.Īnother option is removing parts of the code and data to localise the bug. If logging is possible, concentrate less on the data, but more on the flow of the program, until you know in which part it happens. The error happened only after several hours and even a single line of output slowed down things so much, that it would have taken days. I had to debug something similar with a neural network once, that processed 100k of nodes per second. In heavy parallel processing this is often not possible. Though in my experience this is often problematic. Sent when a thread enters a Java programming language monitor after waiting for it to be released by another thread. Trigger on some reasonable duration and dump the state information that you are tracking.Īt some point, plain old code inspection is going to be necessary.įirst step (as Péter says) is logging. Sent when a thread is attempting to enter a Java programming language monitor already acquired by another thread. Build a monitor thread that checks how long threads have been blocking. Track what threads have each mutex and what threads are waiting on the mutex. This should help you identify the thread that is involved in the issue.Īnother thing that you could try is building a wrapper library around your mutex/semaphore services. This article will describe the complete root cause analysis of a recent Java deadlock problem observed from a Weblogic 11g production system running on the IBM JVM 1.6.This case study will also. FindBugs 22 reports an alarm when a thread invoking a condition. Use function failure code's/conditions to log a pseudo stack trace after the timed wait fails to identify how you got there in the first place. However, existing deadlock detection tools mainly focus on locks, but cannot detect. Depending the variability of the timing you might get lucky and find both locks after a few runs. This will at least point you in the direction of one of the locks that is involved in the issue. Change all the mutex/semaphores that wait forever to timed waits.something ridiculously long like 5 mins. It's certainly possible you will not find the problem before you run out of time or money.Īs others have said.if you can get useful information for logging then try that first as it is the easiest thing to do. At each lock, determine whether a thread holds other locks, and if so, under what circumstances another thread, doing a similar execution path, can get to the locking event under consideration. Painstakingly work through a thread's execution, and examine all locking events. Even better, ensure that a thread holds only one lock at a time. If you can, ensure that a thread unlocks in reverse order from locking. It's hard to emphasize this enough: assume nothing.Īfter that, determine what locks get held while a thread attempts to lock something else. You may want to remove all comments from the code you're looking at, as those comments may cause you to believe something that doesn't hold true. two threads hold two different locks, but at least one thread wants a lock the other thread holds) then you need to first abandon all pre-conceptions of how the threads order locking. If the situation is a real deadlock (i.e.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |