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.

沒有留言:

張貼留言