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). 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. Simply remove the de.tobject.findbugs0.0.n directory from Eclipses plugins directory. If you have previously installed a version of the FindBugs plugin prior to mid-May, 2006, then you should remove it first. The plugin runs under Java 1.5/5.0, or newer. Though in my experience this is often problematic. The plugin is not compatible with versions of Eclipse preceding 3.3. ![]() 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. 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. Here is a a quick sample that shows the deadlock situation explained above with good old sync blocks.If the situation is a real deadlock (i.e. ![]() Deadlocks usually occur when the order of locks is not consistent throughout the application. In this case, threads are deadlocked because they are each waiting for the other thread to release the other lock and your application just hangs. Thread1 acquires lock1 and is about to acquire lock2 while thread2 acquires lock2 and is about to acquire lock1. ![]() Previous Topic: Difference between Thread.yield () and Thread.sleep () methods. Next Topic: Starvation in java with example. 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. Output: Thread1 locked resource3: Prabhjot Thread1 locked resource2: Nidhi Thread1 locked resource1: Amani Download this example. Alphonse and Gaston are friends, and great believers in courtesy. Imagine you have two threads, thread1 and thread2. Deadlock describes a situation where two or more threads are blocked forever, waiting for each other. In this post, I want to talk about deadlock detection in Java and some pitfalls you might run into.Įvery programmer knows what a deadlock is but for completeness sake, I’ll give a brief description.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |