Nested Monitor Lock Management for Java Thread Deadlock Prevention

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing methods for managing nested monitor locks in Java™ can lead to deadlocks when custom class loaders break serialized class loading, causing applications to fail as threads wait indefinitely for the release of inner and outer monitors, violating lock ordering rules.

Innovation Solution

A method that preserves and restores the processing state of threads to safely release and reacquire outer monitor locks, allowing threads to complete processing without deadlocks, by using internal JVM APIs to manage recursive lock counts and maintain lock ordering, enabling threads to acquire and release monitors in a controlled sequence.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If custom class loaders break serialized class loading to enable parallel thread execution, then productivity is improved, but deadlocks occur due to violated lock ordering rules

Engineering Contradiction:
Improveparallel thread executionVSAvoiddeadlock prevention
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

The patent applies preliminary action by preserving the processing state (including lock counts and monitor ownership information) before threads release outer monitors. This allows the system to restore the exact state later, ensuring that lock ordering rules are maintained even when threads execute in parallel. The preservation of state before monitor release prevents deadlocks by ensuring that when monitors are reacquired, the proper ordering is restored.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent changes the parameter of monitor lock management by introducing a mechanism where threads can temporarily release outer monitors while preserving their lock count state. This allows the system to transition from strict serialized execution to controlled parallel execution, improving productivity while maintaining reliability through state preservation and restoration.

Inventive Principle:
Principle #35Parameter changes

2Reliability

If threads acquire outer monitors multiple times (recursive locking) to protect critical code, then reliability is improved through proper mutual exclusion, but threads may wait indefinitely for monitor release causing deadlocks

Engineering Contradiction:
Improvemutual exclusion controlVSAvoidthread waiting time
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The patent applies preliminary action by preserving the processing state including lock counts before threads release monitors. This ensures that when monitors are released and later reacquired, the correct number of acquisitions is restored, preventing indefinite waiting and ensuring proper mutual exclusion is maintained without deadlocks.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent implements feedback by tracking and preserving the recursive lock count state. The system monitors how many times a thread has acquired a monitor and uses this information to ensure the correct number of releases occur. This feedback mechanism prevents threads from waiting indefinitely by ensuring that monitor release and reacquisition follows the proper sequence.

Inventive Principle:
Principle #23Feedback

3Productivity

If the wait() operation completely frees a monitor for other threads, then productivity is improved through better resource utilization, but lock ordering rules are violated causing deadlocks

Engineering Contradiction:
Improveresource utilizationVSAvoidlock ordering compliance
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

The patent applies preliminary action by preserving the processing state before the wait() operation releases the monitor. When a thread calls wait() and releases a monitor, the system has already recorded the lock count and ownership state. This allows the monitor to be freed for other threads (improving productivity) while ensuring that when the waiting thread is notified and reacquires the monitor, the lock ordering rules are restored (maintaining reliability).

Inventive Principle:
Principle #10Preliminary action

Data Source

PatentUS7681197B1Nested monitor handling processes
Publication Date: 2010.03.16 ORACLE AMERICAN INC
  • US7681197B1 patent drawing
  • US7681197B1 patent drawing
  • US7681197B1 patent drawing

AI summary

A method of managing nested monitor locks in a computer program is provided for an application having at least a first thread and a second thread wherein a non-synchronized procedure is processed by the application. The first thread executes an outer software module while the second thread executes an inner software module. A processing state of the second thread code is preserved before the second thread is configured to release an outer monitor of the outer software module. The first thread acquires the outer monitor of the outer software module so that actions may be completed. Upon completion of actions by the first thread, the outer monitor of the outer software module is released. The processing state of the second thread is restored, such that, actions of the second thread are allowed to be completed.