문제

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.

도움이 되었습니까?

해결책 2

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.

다른 팁

You can use EJB TimerService feature. Using threads in a managed environment should be avoided.

I think, its possible with some advanced Threading approach. More than thinking on manual synchronizations and thread management, you can always use the Java Concurrent package.

Future can be one of the ways to do this. Please refer to Java Concurrent package.

Use notifications and Object#wait() / Object#notifyAll() i.e. Multithreaded, the producer notifies the consumer.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top