![]() ![]() 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. While multi-threading helps in improving an applications performance, it also comes with some problems. Ive created a simple monitoring python program that checks remote servers over ssh using paramiko and fabric api, now I want to find out if a deadlock occurred in remote servers java program. 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). 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 case of deadlock, details are logged for subsequent reproduction. We first run ‘Stalemate’ to generate a list of potential deadlocking classes. In heavy parallel processing this is often not possible. In this work we combine a static approach (Stalemate) and a dynamic approach (Omen) to detect deadlocks in large Java libraries. This can lead to a system-wide stall, where no process can make progress. A deadlock occurs when two or more processes are blocked, waiting for each other to release the resources they need. Though in my experience this is often problematic. Deadlock detection and recovery is the process of detecting and resolving deadlocks in an operating system. 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. 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. 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. Depending the variability of the timing you might get lucky and find both locks after a few runs. If any deadlocks are detected, it prints additional information after the thread dump on each deadlocked thread. 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. We should also avoid giving locks to members or threads which do not need it. 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. The JVM can detect cycles that consist of locks that are obtained through synchronization, locks that extend the .AbstractOwnableSynchronizerclass, or a mix of both lock types. 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. the JVM attempts to detect deadlock cycles. 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. I'll describe three techniques in this text: Lock Ordering Lock Timeout Deadlock Detection Deadlock Prevention Tutorial Video If you prefer video, I have a video version of this deadlock prevention tutorial here: Deadlock Prevention in Java. In one of the mock exams there was an exercise to name from what threading problem does the code suffer.If the situation is a real deadlock (i.e. Jakob Jenkov Last update: In some situations it is possible to prevent deadlocks. I'm preparing for Java SE 7 Programmer II exam. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |