How to avoid Deadlock in java?
Deadlock rises when several Threads are trying to access some resource and one thread is waiting to another thread to complete its execution and release the lock while executing thread is also trying to acquire another resource which is in execution and it is also trying to acquire another resource which is acquired by another thread, all the threads are waiting for some another thread to complete its execution and release and lock and hence all the threads are in waiting thread forever, this dependency to one another for acquiring resource is called Deadlock. To avoid such problem we can follow these:
do not share data to multiple thread if sharing make data immutable instead of using synchronization.
avoid nested lock and release the lock immediately after completing execution
lock parts of the code which you need to required rather than locking it globally.
avoid using Multi-Thread if you are using make sure the thread acquire/release the lock in certain order.
look for another alternative because using synchronized keyword will reduce the performance time.
· if any one event of the blocked state (Blocked states like wait(),sleep(),blocked on I/O,blocked on join,blocked to lock) occurs
· permanently,then the thread is under Deadlock
· so we can use "isAlive()" method to check the Deadlock or Livelock
· if(t1.isAlive())//t1 thread
· {
· t1.resume();
· }
· else
· {
· t1.destroy();
· }?
Any Further Clarification please visit
http://srimanjavagroup.com/1/forum.htm














