This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes BEA/Weblogic and the fly likes executing main periodically in weblogic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "executing main periodically in weblogic" Watch "executing main periodically in weblogic" New topic
Author

executing main periodically in weblogic

Andrew Cane
Ranch Hand

Joined: Aug 07, 2013
Posts: 91
I've created a project with one main function. The main function will perform a routine database cleanup every 5 minutes. Does anyone know how to do this in weblogic 10.3? should I deploy in jar? or exploded folder will be okay? Should I put the main function inside servlet? thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Web apps don't have main functions. But ...

Rather than try to stuff it into weblogic, why not just run it as a scheduled cron job (or whatever the equivalent is on your platform)? Trying to stuff it into a web app is not necessary or advised.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Andrew Cane
Ranch Hand

Joined: Aug 07, 2013
Posts: 91
Thank you for the quick reply, good Sir. So, how do we do that? I deply the said application as jar and create the cron job in LINUX (my server is using LINUX)?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

If your server is Linux, then a cron job is the way to go. It can start up the Java app periodically so that it can perform its cleanup and then exit.
Andrew Cane
Ranch Hand

Joined: Aug 07, 2013
Posts: 91
okay, lets say I've modified the main method to use ScheduledExecutorService and Runnable methods so the main method will do the cleanup periodically, that would mean I don't need to create the cronjob? thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42371
    
  64
Theoretically you wouldn't. But the job may crash, and would need to be restarted by hand. Or the machine is rebooted. Or you want to pause it. All these scenarios are handled easily if the job gets executed via cron (instead of having it run all the time and doing the scheduling internally). So I would still advise to use a cron job for starting it.


Ping & DNS - my free Android networking tools app
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
Also if you make the script a database script then you don't even need to start a JVM at all. Just execute the SQL script from cron. There is really no need to use a JVM let alone weblogic for this.
Andrew Cane
Ranch Hand

Joined: Aug 07, 2013
Posts: 91
okay, thanks guys.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: executing main periodically in weblogic