How to resolve deadlock in Java?

There are some guidelines which if used properly when writing a multi-threaded application can help avoid deadlock situation in an application. The guidelines are officially released by Oracle:
1) Try not to hold locks across long operations like I/O where performance can be adversely affected.
2) Do not hold locks when calling a function that is outside the module and might reenter the module.
3) In general, start with a coarse-grained approach, identify bottlenecks, and add finer-grained locking where necessary to alleviate the bottlenecks. Most locks are held for short amounts of time and contention is rare. So, fix only those locks that have measured contention.
4) When using multiple locks, avoid deadlocks by making sure that all threads acquire the locks in the same order.

People who read this post also read :



1 comments:

Did you know that you can earn dollars by locking selected pages of your blog / website?
All you need to do is open an account with AdscendMedia and implement their Content Locking plug-in.

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More