Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6778575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:16:55+00:00 2026-05-26T16:16:55+00:00

Sample Code: @Singleton @Startup public class EBlastScheduler { @Resource TimerService timerService; EBlastScheduler what =

  • 0

Sample Code:

@Singleton  
@Startup  public class EBlastScheduler {

    @Resource
    TimerService timerService;
    EBlastScheduler what = new EBlastScheduler();
    @PostConstruct
    public void initialize(){
       if (timerService.getTimers() != null) {
           for (Timer timer : timerService.getTimers()) {               
               if (timer.getInfo().equals("EBlastScheduler")){

                   timer.cancel();
               }
           }
       }


        ScheduleExpression expression = new ScheduleExpression();
        expression.second("*/1").minute("*").hour("*");
        timerService.createCalendarTimer(expression);
    }

    @Timeout
    public void execute(Timer timer){
        System.out.println("----Invoked: " + System.currentTimeMillis());
    } }

I just wanted to make a timer service that can handle the change in schedule of its timeout by canceling the former schedule if the new one is set. In my case, I can’t figure out how to do this in EJB 3.1 especially because I am new to this framework. Your help will be mostly appreciated. 😀

I want something like this:

EBlastScheduler ebs = new EBlastScheduler(ScheduleExpression sExp); //
this line of code must change the current scheduled time of the scheduler to the newly set’ed
time.

NOTE:

I wanted to access this class remotely; and by passing new
schedule as parameter/s, this class must change its timeout
accordingly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:16:56+00:00Added an answer on May 26, 2026 at 4:16 pm

    You can have stateless a bean, which can be used as a utility for managing timers in the system. It will be responsible for performing operations on them – create/cancel timers.

    The purpose is to decouple the timer operations from the startup class, then you can modify them at particular point of time.

    But utility bean must be initialized before EBlastScheduler, which is a startup bean, for that you have to annotate it with the annotation @DependsOn("TimerUtilityBean").

    Below is the sample code, might need some modifications.

    EBlastScheduler.java

    @Singleton 
    @Startup
    @DependsOn("TimerUtilityBean") 
    public class EBlastScheduler {
    
    @EJB
    TimerUtilityBean timerBean;
    
    @PostConstruct
     public void initialize(){
      timerBean.cancelTimer("EBlastScheduler");
      timerBean.createTimer("*/1", "*", "*");
     }
    }
    

    TimerUtilityBean.java

        @Stateless
        public class TimerUtilityBean {
    
        @Resource
        TimerService timerService;
    
         public void createTimer(String sec, String min, String hour){
    
            ScheduleExpression expression = new ScheduleExpression();
            expression.second(sec).minute(min).hour(hour);
            timerService.createCalendarTimer(expression);
         }
    
         public void cancelTimer(String timerInfo){
    
          if (timerService.getTimers() != null) {
    
               for (Timer timer : timerService.getTimers()) 
                   if (timer.getInfo().equals(timerInfo))
                       timer.cancel();
           }
         }
    
         @Timeout
         public void execute(Timer timer){
            System.out.println("Invoked: " + System.currentTimeMillis());
         }
    
         public void reinitializeTimer(String sec, String min, String hour, String timerInfo){
            cancelTimer(timerInfo);
            createTimer(sec, min, hour);
         }
    }
    

    Now, you can use TimerUtilityBean to manage timers from anywhere within the application. Can access it remotely & will be able to pass new schedule parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sample code: public class Service1 { public int Service1() { .... } } public
Early warning - code sample a little long... I have a singleton NSMutableArray that
The classic of writing a singleton in java is like this: public class SingletonObject
I saw the following code: http://sourcemaking.com/design_patterns/singleton/cpp/1 class GlobalClass { private: int m_value; static GlobalClass
Sample code that shows how to create threads using MFC declares the thread function
Sample code <asp:Repeater> <ItemTemplate> <asp:ListView DataSource=<%# Container.DataItem.Items %> ... /> <asp:DataPager .... /> </ItemTemplate>
In sample code, I have seen this: typedef enum Ename { Bob, Mary, John}
Searching for some sample code for converting a point in WGS84 coordinate system to
Here is my sample code: from xml.dom.minidom import * def make_xml(): doc = Document()
Here is a sample code to retrieve data from a database using the yield

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.