Beh01der / EasyFlow

EasyFlow - Simple and lightweight Finite State Machine for Java
http://datasymphony.com.au/open-source/easyflow
Apache License 2.0
442 stars 87 forks source link

Refactoring synchronized/notify constructs to CountdownLatch #1

Closed maximdim closed 11 years ago

maximdim commented 11 years ago

In my case, test never finishes with original synchronize/notify approach for flow.waitForCompletion() (see SynchronizationTest.java). I have refactored it to CountdownLatch - think it's a bit cleaner this way as well.

Beh01der commented 11 years ago

Thanks for contributing, Dmitri. It looks better this way indeed.

However, there is a little problem with your test. You specified SyncExecutor for the flow, and this executor runs on the same thread where the flow was started. Therefore, by the time you call waitForCompletion, it's already completed. With SyncExecutor there is no need in waitForCompletion call.

maximdim commented 11 years ago

Andrey,

Indeed you're right, now when I look at it it makes sense, but it wan't immediately obvious when I wrote code initially. I think that correct behaviour for waitForComplation() in such case should be not too block at all, which is what achieved with the patch. Glad you found it useful.