Hi stan,
Deadlock occurs when two (or more) threads hold a lock that the others need to complete.
e.g.
Thread A holds a lock on object 1 and needs a lock on object 2 to complete.
Thread B holds a lock on object 2 and needs a lock on object 1 to complete.
Your code starts two Threads (incidentaly the name TransThread1 is a bit misleading as its not a Thread) which use the same Runnable object.
For the first Thread the str member of the Runnable object *may* be set to "Method" when it gets to the place in the run() method that uses it.
For the second Thread the str memeber of the Runnable object *will* be set to "Method".
As your using separate Threads, each could run before, after or concurrently with the other.
You're getting a lock on an object which changes at run time - probably not what you intended i.e. the objects created for "" and for "Method" have different locks and if str member has been changed the second thread will always successfully get the lock regardless of whether the original thread holds the lock for a different object.
In addition, you always get the locks in the same order. Even if the same object is synchronized on, the second thread will just wait until the first releases the lock and then go about its business.
In short, if you want to see deadlocking in all its glory you'll need to change your runnable class to do something like
Hope this makes sense,
Jeremy.
[ May 25, 2004: Message edited by: Jeremy Thornton ]