Search code examples
databaseejbpolling

Best approach to poll information from a database within an EJB


I am trying to poll information from a database in an EJB. Specifically, I need to check if a condition is met before proceeding with other business logic in the EJB. Does anyone know what would be the best approach to tackle this? I am thinking of some sort of job scheduler that polls the info from the database, and once the condition is met then it would notify the EJB to continue. I believe that using Thread.sleep in a loop during a transaction would be a bad idea, but I am not really sure. Thanks for the help.


Solution

  • Well, after much research I ended up using an EJB timer and the @Asynchronous annotation on an EJB method (both methods worked well). The idea is that I set up those timers to query the database periodically and check if the condition I was interested in was met.