Search code examples
javasleepjava-ee-5

How to delay processing reasonably in Java EE context?


Within a Java EE 5 environment I have the problem to ensure the existence of some data written by another part before continue processing my own data.

Historically (J2EE time), it was done by putting the data object to be processed into an internal JMS queue after waiting for e.g. 500ms via Thread.sleep.

But this does not feel like the best way to handle that problem, so I have 2 questions:

  1. Is there any problem with using the sleep method within an Java EE context?
  2. What is a reasonable solution to delaying some processing within an Java EE 5 application?

Edit:

I should have mentioned, that my processing takes place while handling objects from a JMS queue via an MDB.

And it may be the case, that the data for which I'm waiting never shows up, so there must be some sort of timeout, after which I can do some special processing with my data.


Solution

  • I agree with @dkaustubh about timers and avoiding threads manipulation in JavaEE.

    Another possibility is to use JMS queue with delayed delivery. Although it is not a part of JavaEE API, most of messaging systems vendors supports it. check here.