• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Thread Scheduler

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I have a task here and needed some inputs from you guys.
This task needs to be done using jdk1.4 only in weblogic 9 server

I have written a small thread which runs as a start up class once i a start my weblogic server.

Example:

I am making this thread poll the database every 5 min to check is there are any invalid recrods and if they are found This thread deletes it and sends email to user.
This works fine.

Now I have to also add one more new task to this in the same class.
I have to also send emails every midnight about the records in the database.

Here is where i am facing problem.

suppose i start my weblogic server at 5.00 pm then my program needs to calculate the midnight time and trigger exactly at midnight and there after run every midnight. simultaneously the polling mechanism i wrote should run as i have implemented every 5 min.

How can i achieve this in the same class? Do I need to start a seprate thread?
I came across a article which says timer task and timer in jdk1.4 should not be used in a managed environment like weblogic container as it runs a thread which is out of the scope of weblogic.

How do i go about this?








 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nilesh Raje wrote:I came across a article which says timer task and timer in jdk1.4 should not be used in a managed environment like weblogic container as it runs a thread which is out of the scope of weblogic.



Any thread YOU create, if it is a Timer/TimerTask or Thread t = new Thread() is not managed by the web container. Some people (me included) don't like to do this. The JVM for the application container should be used for the web application(s) only and are best managed by app server. That is my opinion, anyway.


So I usually suggest to have your web container trigger an external application to start/stop at the correct times. For example, you polling/record management application doesn't really have much to do with the web app, so why put it in weblogic at all. Have a standalone service which polls the DB every 5 minutes and, at midnight sends an email. Weblogic would start the service when weblogic itself starts up and end the polling service when weblogic shuts down. In this case you could either use Timer/TimerTask or your OS' scheduling software to run the polling job.

If, on the other hand, you really want to run the task inside weblogic, then you are going to have to make a Thread, and this Thread will be outside weblogic's management in any case, so using a Timer/TimerTask is no different than your current solution in that regards. Timer/TimerTask does give you a lot more benefit in how the scheduled task occurs, so I would suggest the Timer/TimerTask solution.
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If, on the other hand, you really want to run the task inside weblogic, then you are going to have to make a Thread, and this Thread will be outside weblogic's management in any case, so using a Timer/TimerTask is no different than your current solution in that regards. Timer/TimerTask does give you a lot more benefit in how the scheduled task occurs, so I would suggest the Timer/TimerTask solution.



To be fair, this is actually common -- sometimes, it is just not possible to avoid starting another thread.

BTW, you also never mentioned what is the application type -- servlet? EJB? MBean? Web Service? Some of those types have start and stop methods (callbacks), that can be used to help manage the threads.

Henry
 
Henry Wong
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This task needs to be done using jdk1.4 only in weblogic 9 server



BTW, I don't think that this is a valid configuration, as I believe that Weblogic 9 requires Java 5.

Henry
 
Nilesh Raje
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the configuration is valid and set up as per requirement.

Weblogic uses jdk1.5 but my application needs to use compile time JDK1.4 and runtime JRE1.5 as in this thread I am taking a handle to a EJB which is again compiled in jdk1.4 and run in jdk1.5 runtime.

Anyways I dont have any issues with configurtion cause thats how it has to be.

I could have scheduled this using unix cron but the requirement is to startup up with the server only. This has to start up with weblogic.

Well coming back to the question i raised. I have used Quartz for this.I found this pretty handy.
For more info here is the url http://www.opensymphony.com/
Timer and Timer task are not good options as they have a overhead and performance hit. I found several articles for this.

Here is what i have come up with now.

I have 2 classes which do 2 different tasks And the scheduled them in one class.


This class is for task 1.



This class is for task 2.



This is my main scheduler.



 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic