JVM fundamentals workbench
Change one condition, predict the outcome, then run the model. Each run starts from the stated fixture.
Incident 1 · A report stops responding
A request needs a JDBC connection to run a report. The pool lends connections up to a configured maximum. Both incidents below start with one connection borrowed out of one. Both reports eventually return 18. Before revealing the answer, decide which report could finish sooner if you added a second connection.
Evidence captured on JDK 21
- A. The request is TIMED_WAITING. Its stack includes
Thread.sleep, thenJdbcConnectionPool.getConnection, thenJdbcIncident.readTotal. - B. The request is BLOCKED entering a synchronized region. The dump identifies the main thread as the monitor owner. The waiting thread has yet to enter
readTotal.
Compare your diagnosis
Only A can use the second connection immediately. Its worker is already trying to borrow one. In B the worker must acquire a Java monitor before it can even ask the pool. At capacity two, B still waits while only one connection is borrowed. In both runs releasing the owner ultimately returns the pool to zero borrowed connections. The full-pool gauge alone gave the same reading for two different causes.
Incident 2 · The request already has a connection
Two connections see a committed seat at revision 1. The first transaction changes it to revision 2 and stays open. The second can still read revision 1 and update a different seat. Its attempt to change this same seat times out. Where is the wait now?
The second caller retries UPDATE seat SET revision=3 WHERE id=1 AND revision=1 after the first caller finishes. Predict the affected-row count and final revision if the first caller commits. Predict both again if it rolls back.
Check both transaction endings
The second caller has already borrowed a connection and executed other SQL. Its same-row write conflicts inside the database. After commit the stored revision is 2, the predicate matches zero rows and the caller must reconcile its stale edit. After rollback revision 1 is visible again, the retry changes one row and revision becomes 3. The initial lock timeout was an exception. The later zero-row result was a successfully executed conditional update.
Reproduce both incidents locally
Save JdbcIncident.java, RowWait.java and the H2 2.3.232 JAR in one directory. From that directory use JDK 21 to run the commands below. Each run creates a fresh in-memory database. The evidence above lets you work both cases on a phone.
java -cp h2-2.3.232.jar JdbcIncident.java A 1
java -cp h2-2.3.232.jar JdbcIncident.java B 1
java -cp h2-2.3.232.jar JdbcIncident.java A 2
java -cp h2-2.3.232.jar JdbcIncident.java B 2
java -cp h2-2.3.232.jar RowWait.java commit
java -cp h2-2.3.232.jar RowWait.java rollback
Keep the request stack, the before-release pool counters, and the two retry results. Thread frames and database timeout codes are specific to this fixture. For a production incident, collect the corresponding connection, request and database evidence from the actual driver and database.