Reputation: 842
What is the best solution for an ejb that needs to "wait" for data? I have an ejb that goes and checks a database table for some data, if the data is not there it needs to wait x number of seconds and check again. I know that Thread.sleep/Thread.wait and such manipulation is not recommended in the Java EE spec. However there has to be a realistic solution to this problem. Some other reading has suggested that you must kick off a timer or something however I really do need to block the requesting call until this data is available which eliminates the schedule or timer solution. Any other ideas?
Upvotes: 0
Views: 1258
Reputation: 8876
You can use and EJB Timer to do this, but honestly "polling" for data is a waste of resources. A better way is to use JMS. Have you producer of the data put the data in the database, then put a message on Queue. Both the message and database write will commit together in the same transaction. All you do after that is have a listener on the JMS queue that triggers when a message arrives. And there you go, no "polling needed."
If you need specific examples, let me know I can extend my answer a bit.
Upvotes: 2