5 Replies Latest reply on Nov 19, 2013 5:24 AM by aqtwrdnr

    EJB solution for doing something small 10 times per second

    aqtwrdnr

      Hello,

       

      I want to post 10 messages per second from a Stateless EJB to a JMS queue. Currently I have an asynchronous method with a while loop that posts a message to the queue and sleeps 100 millisecond, then posts another message to the queue and sleeps 100 milliseconds, etc.

       

      I am wondering if it is better to use the timerservice (with a timeout of 100 milliseconds) for this purpose. And more specifically; is the timer service suited for this kind of usage? The timing does not have to be accurate on the millisecond.

       

      Thanks in advance!

        • 1. Re: EJB solution for doing something small 10 times per second
          welle

          Hi

           

          From what I remember the EJB3 scheduling can only be configured on seconds and not ms (but I can be wrong so look it up in the schema or spec).

           

          What is the purpose of sending these "timed" messages to an asynchronous service like JMS (that will NOT consume them respecting the "timing")?

          • 2. Re: EJB solution for doing something small 10 times per second
            aqtwrdnr

            Hello welle, thanks for your reply.

             

            The EJB 3.1 specs indeed say:

            While timer durations are expressed in millisecond units, this is because the millisecond is the

            unit of time granularity used by the APIs of the Java SE platform. It is expected that most timed

            events will correspond to hours, days, or longer periods of time.

            The purpose is polling a particular URL for changes that occur. Since the duration of internet I/O operations are unpredictable, we decouple the execution of the HTTP GET requests from the process that creates the requests 10 times per second. A set of Message-Driven Bean's handle the execution of the actual requests and check for changes.

             

            Any ideas for improvement?

             

            Thanks in advance!

            • 3. Re: EJB solution for doing something small 10 times per second
              nickarls

              It appears quite a complicated solution just to poll a web site for changes(?)

              • 4. Re: EJB solution for doing something small 10 times per second
                rhusar
                Since the duration of internet I/O operations are unpredictable, we decouple the execution of the HTTP GET requests from the process that creates the requests 10 times per second.

                I wonder if this is even a good approach. Are you using all the data or only the latest?

                • 5. Re: EJB solution for doing something small 10 times per second
                  aqtwrdnr

                  Thanks for all your replies.

                   

                  nickarls: Maybe you are right. What would be your approach?

                   

                  rhusar: What do you mean by "Are you using all the data or only the latest?" The response of each request is checked and if it satisfies certain conditions, we take some action. So, all responses are used for at least some part (to check for changes) and the 'last' one is used entirely (parsed, etc).