Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Best approach for an async Service that works on a request input queue

AndipaNov 12 2013 — edited Nov 13 2013

I have sort of a queue of requests to which I'm able to add new ones from various parts of the application.

My JavaFX-Service should then process these requests in an asynchronous, but coordinated manner.

My current approach is to use an ObservableList for the queue. I have a listener on its emptyProperty and trigger the service restart everytime it changes from empty to not empty.

In my service's task I take the first element of the list, process it and when the processing succeeded (or failed), remove it from the list.

Then however I have to check in the succeeded() and failed() methods whether there are more elements and restart the service in case there are.

It feels needlessly complicated and potentially error-prone. Isn't there a simpler approach I'm missing?

This post has been answered by jsmith on Nov 13 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2013
Added on Nov 12 2013
2 comments
354 views