area9innovation / flow9

Platform for safe, easy and productive programming of complex, multi-platform apps with a modern user interface
Other
569 stars 37 forks source link

Improve java SingleExecutor #1398

Closed Eugeny48 closed 1 month ago

Eugeny48 commented 1 month ago

We do not need a queue in SingleExecutor, i.e. it should be good to use an empty queue -- SynchronousQueue. But for some reason SynchronousQueue does not work correctly sometimes: when previous task is done, queue does not accept a new task:

Task java.util.concurrent.FutureTask@3e6bdb53[Not completed, task = com.area9innovation.flow.DatabaseSValue$$Lambda$1400/0x0000000840647040@6ef980b8] rejected from com.area9innovation.flow.FlowRuntime$SingleExecutor@2b1aae93[Running, pool size = 1, active threads = 0, queued tasks = 0, completed tasks = 3524

It looks like the task is done, but the worker thread is not ready to accept a new task. So now we are using queue with capacity 1. To prevent multiple execution SingleExecutor.activeTasks is used in couple with the builtin reject policy (but the builtin reject policy cannot reject second execution, only third and more).