Larry
Larry

Reputation: 11949

Asynchronous continuous polling of data from DB pushed to Java-client

Could someone suggest what’s the best approach to go about this:

What I like to do is draw a continuous poll (or query) of a database table. And anytime a new update has occurred, I want to push this to the client in a Java application. The idea is users can suggest what data they want to subscribe to and define an event-handler to handle any incoming data.

I therefore need to have the polling being done in the background. But I seem to having trouble with doing this correctly. I’m looking at using a simple event bus for local JVM pub/sub, but I can’t seem to get the asynchronous continuous polling going.

Upvotes: 1

Views: 3556

Answers (2)

jiggy
jiggy

Reputation: 3836

Have a look at java.util.concurrent. You can create a scheduler to run at a given interval utilizing a thread pool like with a ScheduledThreadPoolExecutor.

Upvotes: 1

AlexR
AlexR

Reputation: 115398

Your solution has a lot of disadvantages.
A better solution is to create business logic that is responsible for saving data in the database and for notifications. You can for example create an application that is subscribed to JMS topic. Another component receives calls to process and save data. It stores data and then sends notification of this action. All components subscribed to the topic receive this notification and react accordingly.

Upvotes: 2

Related Questions