Here is working code. Please suggest ways to ensure deadlock or increase the probability of deadlocking :
SCJP 6. Learning more now.
posted 6 years ago
You want a deadlock?
Easiest way to get a deadlock is to have the two threads require a lock on two separate objects, but for them to acquire them in different orders. For example:
In your example, it appears that the first thread is always synchronizing on h, and the second on h2. They share the same static int, so you may well get confusing behaviour, but I don't see how a deadlock can occur. You need both threads to be waiting for each other.