troubleshooting Question

how do i make deadlock

Avatar of cofactor
cofactorFlag for India asked on
Java
31 Comments1 Solution423 ViewsLast Modified:
I  read the following texts to create a deadlock.

in general, deadlock occurs when two or more threads each obtain two or more locks, but don't obtain them in the same order:

// T1
synchronized (a) {
    synchronized (b) {
    }
}
 
 
// T2
synchronized (b) {
    synchrnoized(a) {
    }
}





Now, i want to create a deadlock which conforms the above.

but i am confused how to write..

few issues i am stuck..
1)whether T1 and T2 are generated  from the same class .
2)whether a,b are the objects of the same shared resource.
3)how do i write the above sychronized methods ? see, Runnable class has only 1 method run() for thread activities .....how do  i write there 4 synchronized statements in it ?


I will appreciate if you please  provide me a deadlock code which conforms the above  code snippet.
ASKER CERTIFIED SOLUTION
Ajay-Singh

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 31 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 31 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros