Results 1 to 6 of 6

Thread: Scheduling in EJB3 Timer Service

  1. #1
    Join Date
    Apr 2010
    Posts
    72

    Scheduling in EJB3 Timer Service

    I am trying to make the project (basic things ) in Java. In that I am confusing in Timer Service. So I need your help for an explanation of that.!! Please tell me about the scheduling in EJB3 Timer Service. Since you members are good at programming language, I am sure that someone will definitely help me. The only thing is that I am expecting detailed information from your side. Any sample of coding will be very helpful.

  2. #2
    Join Date
    Dec 2008
    Posts
    202

    Re: Scheduling in EJB3 Timer Service

    I think that before knowing about the scheduling in EJB3 timer service, you should know about the basic things. Scheduled tasks are a reality in JEE applications: tables must historicize, alarms should be generated, ... Normal may be the definition of a batch process that is invoked periodically through the Windows Task Scheduler, and UNIX, via cron, or some commercial solution type control-M. The main benefit of its use is that, as part of standard, we do not tie ourselves to a particular application server. EJB3 Time Service allows you to specify a method that is called automatically after a certain time interval.

  3. #3
    Join Date
    Apr 2008
    Posts
    193

    Re: Scheduling in EJB3 Timer Service

    Implementing an EJB Timer Service is really simple. We talked about EJB3, which involves talking annotations and injection of services:
    Code:
    <span <span> style="direction: ltr; text-align: left" com.autentia.tutorial.ejb.scheduler class="google-src-text"> 
    package, import java.util.Calendar; import java.util.Collection; import java.util.Iterator; 
    javax.annotation.Resource import, import javax.ejb.Stateless; javax.ejb.Timeout import, import javax.ejb.Timer;
    javax.ejb.TimerService import, import org.apache. commons.logging.Log; import org.apache.commons.logging.LogFactory; 
    / ** * Implementation IAlarmScheduler @ local service. 
    * / @ Stateless public class implements AlarmScheduler IAlarmScheduler (private static final Log log = LogFactory.getLog (AlarmScheduler.class); 
    / ** Injection of TimerService * / 
    @ Resource TimerService TimerService / ** Time to completion: 23 hours * / 
    private static final int START_HOUR = 23, 
    / ** Minutes Runtime: 0 minutes * / private final static int START_MINUTES = 0, 
    / ** The time of completion: 00 * / private final static int START_SECONDS = 0, 
    / ** Interval Runtime: 1440 = 24 hours * / private static final int INTERVAL_IN_MINUTES = 1440; 
    / ** * Lift service * / 
    public void startUpTimer () (log.info ("startUpTimer - scheduler service alarm is activated."); ShutdownTimer () ; Calendar initialExpiration = Calendar.getInstance (); initialExpiration.set (Calendar.HOUR_OF_DAY, START_HOUR); 
    initialExpiration.set (Calendar.MINUTE, START_MINUTES); initialExpiration.set (Calendar.SECOND, START_SECONDS); long intervalDuration = new Integer (INTERVAL_IN_MINUTES ). longValue () * 60 * 1000; log.info ("startUpTimer - create new timer service at \" "+ initialExpiration.getTime () +" \ "with \" "+ intervalDuration +" \ "interval in milis." ) timerService.createTimer (initialExpiration.getTime (), intervalDuration, null);) 
    / ** * For the service * / public void ShutdownTimer () (Collection </ span> com.autentia.tutorial.ejb.scheduler package, import java.util.Calendar; import java.util.Collection; 
    import java.util.Iterator; 
    import javax.annotation.Resource; 
    javax.ejb.Stateless import, import javax.ejb. Timeout; javax.ejb.Timer import, import javax.ejb.TimerService; 
    import org.apache.commons.logging.Log; 
    import org.apache.commons.logging.LogFactory; 
    / ** * Implementation IAlarmScheduler @ local service. * / @ Stateless public class implements AlarmScheduler IAlarmScheduler (private static final Log log = LogFactory.getLog (AlarmScheduler.class); 
    / ** Injection of TimerService * / @ Resource TimerService TimerService 
    / ** Time to completion: 23 hours * / private START_HOUR final static int = 23; 
    / ** Minutes Runtime: 0 minutes * / private static final int START_MINUTES = 0, 
    / ** The time of completion: 00 * / private static final int START_SECONDS = 0, 
    / ** Interval Runtime: 1440 = 24 hours * / private final static int INTERVAL_IN_MINUTES = 1440; 
    / ** * Lift service * / public void startUpTimer () (log.info (startUpTimer - scheduler service alarm is activated. "); ShutdownTimer (); Calendar initialExpiration = Calendar.getInstance (); initialExpiration.set (Calendar.HOUR_OF_DAY, START_HOUR); initialExpiration.set (Calendar.MINUTE, START_MINUTES); initialExpiration.set (Calendar.SECOND, START_SECONDS); long intervalDuration = new Integer (INTERVAL_IN_MINUTES). longValue ( ) * 60 * 1000; log.info ("startUpTimer - create new timer service at \" "+ initialExpiration.getTime () +" \ "with \" "+ intervalDuration +" \ "interval in milis.") timerService.createTimer (initialExpiration.getTime (), intervalDuration, null)) 
    / ** * For the service * / public void ShutdownTimer () (Collection </ span> <Timer> <span> <span style = "direction: ltr; text- align: left "class =" google-src-text "> timers = timerService.getTimers () log.info (" ShutdownTimer - existing timers? "+ timers) if (timers! = null) (for (Iterator iterator = timers.iterator (); iterator.hasNext ()) (Timer t = (Timer) iterator.next (); t.cancel () log.info ("ShutdownTimer - timer \" "+ t +" \ "canceled. ");))) 
    / ** * callback method is invoked at the end of the interval defined * / public void execute @ Timeout (Timer timer) (log.info (" executing - "+ timer.getInfo ()) / / TODO: Implement the logic of the alarm.)) </ span> timers = timerService.getTimers () log.info ("ShutdownTimer - existing timers?" + timers) if (timers! = null) (for (Iterator iterator = timers.iterator (); iterator.hasNext ()) (t = Timer (Timer) iterator.next (); t.cancel () log.info ("ShutdownTimer - timer \" "+ t +" \ "canceled." );))) / ** * Invoked That callback method at the end of the interval defined * / 
    public void execute @ Timeout (Timer timer) (log.info ("executing -" + timer.getInfo ()) 
    / / TODO : Implements the logic of the alarm .))</ span>

  4. #4
    Join Date
    Mar 2008
    Posts
    227

    Re: Scheduling in EJB3 Timer Service

    The code mentioned by the 'Mecurtis', is not that tough as it seems to be. I have tried to explain you some important things of it :
    • Inject the TimerService on line 23: @ Resource TimerService TimerService;
    • In line 46, he created the timer (timerService.createTimer (...); ) with two parameters: initial implementation (23:00:00 pm) and interval (every 24 hours).
    • The method ShutdownTimer () lists all the timers and kill them one by one. The fact stop the application server does not imply the erasure of the timers, so that if the method does not invoke the method startUpTimer ShutdownTimer before creating a new timer, it would accumulate.
    • Finally, the execute method is marked with the @ Timeout annotation. Will the method is invoked at the appointed time and after each interval.

  5. #5
    Join Date
    Mar 2008
    Posts
    192

    Re: Scheduling in EJB3 Timer Service

    To raise the service you must invoke the method startUpTimer local interface. There may be several ways to do this, we are going to invoke it via a servlet initialization. We define a servlet in our web.xml, which is loaded on server startup:
    Code:
     <span><span style="direction: ltr; text-align: left" class="google-src-text"><servlet> 
    <servlet-name>Initialize</servlet-name> <servlet-class>com.autentia.tutorial.web.servlets.InitAppServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> </servlet></span> 
    <servlet-name> <servlet> Initialize </ servlet-name> 
    <servlet-class> com.autentia.tutorial.web.servlets.InitAppServlet 
    </ servlet-class> <load-on-startup> 1 </ load-on -startup> </ servlet></span>

  6. #6
    Join Date
    Jan 2009
    Posts
    143

    Re: Scheduling in EJB3 Timer Service

    The EJB Timer Service must be properly recorded. Based on the examples of above coding, the following is the figure that shows the EJB Timer Service.


    Perfect for planning tasks scheduled with a minimum cost, since its execution delegate ejb container's application server. We do not have a tool with a GUI administration of these tasks, so if the volume of tasks is high may be a bit tedious administration.

Similar Threads

  1. Sharepoint (MOSS) timer jobs and the timer service
    By MahaGuru in forum Office Setup
    Replies: 2
    Last Post: 01-03-2011, 09:08 AM
  2. Timer Service support for Web Services in EJB 2.1
    By Mei-Xiu in forum Software Development
    Replies: 7
    Last Post: 08-09-2010, 10:03 PM
  3. Transfer of information in the Session Context (Swing Client, EJB3)
    By Protectors in forum Software Development
    Replies: 4
    Last Post: 31-07-2010, 01:49 AM
  4. Execute timer service in java
    By Messenger in forum Software Development
    Replies: 4
    Last Post: 20-07-2010, 01:27 PM
  5. Email Scheduling
    By technika in forum Technology & Internet
    Replies: 5
    Last Post: 12-12-2009, 09:34 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,726,382.38902 seconds with 17 queries