4月 23, 2021

Java threading and resource

 Today I have an strange issue in running a unit test.


In the test, there are a chain of function presumably running in series.

 

The strange part comes in the last for-loop, if I run dijkstra() inside the last func:setupDijkstra() in the for-loop, everything works fine.  

If not included in the last function, things only work fine in step-by-step mode.

After some struggling effort, I solved the problem by joining the last thread in the second last function:initializeADJ.  

Beforehand, the thread fillAdjTable runs after the function body end for just a while after.  My guess is that, by splitting Dijkstra into 2 functions for looping, the function run too soon, the loop being brough forward result in the resource not in a [ready] state.


This feels much like other performance optimization problem.  Small speed up often lead to previously-unknown synchronization issue.

4月 19, 2021

JDBC connection closed exception: an ambiguous error message

 

  做jdbc sql query的時候,一直跳出 connection not open 的提示。經過一番嘗試後才發現,這是因為之前connection 做過 executeBatch(), 但是batch 是empty, 結果完成以後 jdbc connection不能被open 來進行其他statement execution。


但是這個錯誤名也太難混淆視聽了吧???

 

 

 原來係create batch addBatch()過就executeBatch(),結果一直 connection closed bug..