Discussions

EJB design: Implementing Scheduling In An Enterprise Application

  1. Hi Everyone,
    I am writing an Time Sheet Management Application that is using J2EE and is deployed on Weblogic 5.1. In this application I have lot of jobs that need to be scheduled and need to be done periodically for example I have given o users an Auto mode option which causes a Time Sheet for that user to be filled by defdault values and get submitted everyweek. I have implemented this and other scheduling jobs by using JMS. Most of the people suggest using a startup class but since this is not portable code I tried doing it thru JMS. My implementation is as follows your comments and suggestions will be appreciated:

    1. I have defined a producer class that goes into infinite loop and generates messages depending upon events for which I want to do something e.g It generates message every first day of the week.

    2. I have defined an command interface that has single method execute.

    3. I have defined no. of classes each implements execute method and in this method perform a specific task that I want to schedule e.g. look up entity beans , check which user has selected auto mode and submit Time Sheet for him.

    2. I have consumer class that listens to messages generated by the producer. It has a hash table with key value pair with key as message and value is corrsponding class that needs to be executed. Now on the first day of week producer generates a message say "First Week Day". Consumer gets this message lloks up hashtable gets the class as value ,creates a new instance and calls execute method.

    So guys how does it sound.

    Ishtmeet
  2.     Ishtmeet, your architecture sounds good. Congragulations on building a portable scheduling framework. You may also want to check out other solutions like Flux Enterprise Scheduling component from simscomputing.com.

         Specific comments about your design:

    1) I hope you are using Thread.sleep(x) calls in your producer class to ease the cpu utilization of an "infinite loop".

    2) How much of your framework can be configured? For example, I think it would be ultra cool if you could edit a text file to move a job scheduled for tuesday to wednesday, etc.

     
          I also need to do some scheduling here on TheServerSide, but I was just going to use Linux Cron services, I like your solution though!

    Floyd
      
  3. I know, this is not 'portable', but since you are using Weblogic anyway, why not to use Weblogic Time Services?

    If you want portability you can define some abstract API of your own and it's concrete implementation using WLS time services, so, when BEA goes out of business, you can write another implementation not using WLS time services.
  4. Dimitri,

      I would prefer not to use WL time services, so that I don't need to worry about yet another API to learn. :) Linux Cron is a hell of a lot easier, just through a class in the right directory and it works. :)

    Floyd
  5. The WLS time services API is so simple - there is nothing to learn.

    My point was if someone chooses to use Weblogic time services but is worried about portability one possible solution is to inroduce a level of indirection and define your very own abstract API and it's concrete implementation using WLS time services, which can be re-implemented using something else when need arises.

    That way you can use scheduling which comes with Weblogic without reinventing the wheel and without worrying much about portability ;-)
  6. I think I should point out that Flux, the Enterprise Job Scheduler, is far more powerful than WLS time services, has a simple API to use, and is portable across different application servers. It works fine with WebLogic and OrionServer, for example. It was designed that way from the ground up.

    With Flux, there's no need for wheel re-inventing or portability concerns. Flux's Time Expressions really provide a lot of power when it comes to scheduling tasks and jobs. They're more powerful than Unix's cron as well.

    regards,
    david
  7. I just looked at the WebLogic Time Services for scheduling in our project. However, I don't find it powerful enough for our purpose. Main issue:
    o How do you access a scheduled trigger? It should be possible to list all scheduled triggers and possibly cancel them, even after the server is restarted.
  8. Hi Floyd and Dimitri,
    Thanks for your comments as of now this piece of software is picking up the events to be scheduled from properties file and to add or delete new tasks you can add to properties file. However next iteration is to make it as configurable as possible and will be on pattern u suggested.
    And Dimitri I would be grateful if you could elaborate on this not being portable. Because as of now I am using only connection factories of JMS provided by weblogic which will be in any case container dependent and these are also not hardcoded in the program and remaining classes are normal java beans interacting with EJB's and other components.
    Thanks,
    ishtmeet@hotmail.com
  9. I didn't mean that your approach is not portable - I was referring to Weblogic time services ;-)
  10. Hi Ishtmeet,

    I like your solution very much. I also have to do some scheduling and I like the idea of combine the event server with the scheduler.
    You mentioned that you are using Thread.sleep in your producer class until the next message, but if meanwhile you will receive to schedule another task, you need to wake up and change the sleep period.
    did you take it under consideration ? and how ?
    can you elaborate about the design and API of the producer?

    Thanks,
    anat
  11. Floyd,

    you mentioned the use of the Thread.sleep(x) method in the infinite loop? I was always told to NOT use Thread.sleep(x) and synchronization at all in a J2EE environment!!! In fact, I just posted a couple of questions in the design-topic in which I'm asking for a solution different than threading to do asynchronous web applications?

    Besides that, I like the solution for the time scheduling, I think I can pretty much use this :)

    thnx

    Alef Arendsen
  12. Alef,

       You are right, Thread.Sleep should not be used in a J2EE environment, however Ishtmeet's "Producer" class is not a J2EE class, just a regular java class that is running separately, outside of any app. server. So for this class, it is imperative that he use Thread.Sleep in his infinite loop, or risk using all of his box's CPU power.

    Floyd