jraj
jraj

Reputation: 215

Best way to poll a database table for updates from a java web application

I am fairly new to java programming and have a use case where I need to constantly poll about 15 values in a database table for changes from a java web service. If any of the values change, I need to pick up all 15 values from the database and feed my business logic with the real time values. What is the best way to implement this? I was thinking of running a polling thread from within the web service but not sure if that is the correct approach. I would appreciate any help! Thanks.

Upvotes: 0

Views: 1701

Answers (1)

brso05
brso05

Reputation: 13222

You can accomplish this using javascript/ajax:

function refreshData()
{
    //ajax call here call your webservice
    //do updates real time
}
setInterval(refreshData, 15000); //call your webservice every 15 seconds

Another option to avoid any overlap from async ajax calls (if your function takes longer than 15 seconds to run (unlikely)):

function refreshData()
{
    //ajax call here call your webservice
    //do updates real time
    setTimeout(refreshData, 15000);
}
refreshData();

Upvotes: 1

Related Questions