how to make a bean to execute for every scheduled time

Discussions

EJB design: how to make a bean to execute for every scheduled time

  1. hi
    i have a bean which should automatically execute for every scheduled time.
    i have tried to use a standalone thread program which will invoke the bean for everyscheduled time and it is working. but is it the correct appraoch.

    kavitha
  2. hi kavitha,

    if ur using the scheduler which u have created as standalone program in the web based environment it is wrong, us can us JMS to do it. multithreading can't be used efficiently with EJB.
    if i am wrong pl correct me.

    Sreenivas

  3. Your approach is correct, since starting background threads inside your app server is discouraged (since the server cannot track threads it didn't start.)

    JMS is not ths solution here. It is asynchronous, but it's not timed.

    You might want to look at things like Flux which are professional Java scheduling tools.

    CHz

    Tony
  4. I don't see anything wrong in creating a thread within the app server VM, as long as the thread life cycle is managed properly through the server startup and shutdown hooks. I have done it with WLS and called ejb from the thread. I never had any problem.

    Pranab
  5. It's not that you can't do it. You can.

    THe problem comes in that the server cannot manage your thread for you. Moreover, you are using resources which the server is not managing. All other things, such as EJB execute threads etc. are managed by the server using thread pools.

    A given JVM can only (really) run a certain number of threads before performance degrades. So, if you run your own, then you need to reduce the number of threads the server is allowed to run, thus reducing it's ability to service requests from it's various clients.

    Like I said, you can do it, but under very heavy load you have to be careful about how you are affective server managed resources.

    Chz

    Tony

  6. I am pretty sure the approach you are using is right. You have a standalone program i.e. might be like a deamon which uses a scheduler of OS or else you maintain a CRON job.

    This will not have much impact on the Application Server performance. This is going to be just another process running in the Server i.e. not in the process space of APP Server.

    It will be making a call to the session bean periodically and will be just like any other call from the web client (JSP, Servlet).


    Venket
  7. yes venkat
    that's what i did but it's not a daemon thread. it's working perfectly well. i was just not sure about the methodology.
    As tony said we have tried to use Flux tool but it handles lot of other things too which are not necessary for my project.

    kavitha
  8. If WebLogic is your server, there's no need to be fancy - it provides a proprietary API to create schedulers etc. It's not portable, but does anybody really really cares?