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

  • SEARCH
  • Home
  • 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 7745321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:59:07+00:00 2026-06-01T09:59:07+00:00

I have some issues with my EJB 3 timer where it is launched more

  • 0

I have some issues with my EJB 3 timer where it is launched more than once.
Rather than configuring the timer in an annotation, I use programmatic configuration, as explain in many blogs. Here’s my code:

@Singleton
@Startup
public class AutoAssignTask extends AbstractDirectoryMonitor {

    @Resource
    private TimerService timer;

    @Inject
    @PropertyResource(name = "timer.hour", resource = "/DL4/app.conf")
    private String hour;
    @Inject
    @PropertyResource(name = "timer.minute", resource = "/DL4/app.conf")
    private String minute;
    @Inject
    @PropertyResource(name = "timer.second", resource = "/DL4/app.conf")
    private String second;

    @EJB
    private AutoAssignService autoAssignService;

    @PostConstruct
    public void init() {
            // initializing with an expression.
        this.initSchedule();
    }
    protected void initSchedule() {
        ScheduleExpression exp = new ScheduleExpression();
        if (!StringUtils.isEmpty(this.getHour())) {
            exp.hour(this.getHour());
        }
        if (!StringUtils.isEmpty(this.getMinute())) {
            exp.minute(this.getMinute());
        }
        if (!StringUtils.isEmpty(this.getSecond())) {
            exp.second(this.getSecond());
        }
        this.getTimer().createCalendarTimer(exp);
    }

    @Timeout
    public void process() {
        // do something
        AutoAssignTask.LOG.info("starting job.");
    }

Now let’s say I configure the timer for every minute, when I look at my logs I get twice the “starting job” log, proving it starts the job twice.

Any ideas on what is wrong?

  • 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-06-01T09:59:09+00:00Added an answer on June 1, 2026 at 9:59 am

    A few thoughts:

    1. Update the code to show the initSchedule() method. The problem could be in the ScheduleExpression.
    2. You never can rule out server bugs. Check to make sure your @PostConstruct is not called twice which would happen if your server created two singletons (common race condition issue).
    3. As you have some sub-classing, make sure you’re aware that if AutoAssignTask is further sub-classed the @PostConstruct of AutoAssignTask will still be called. More simply put, the @PostConstruct method of an EJB’s super classes are also invoked — the oldest parent first.

    For number 2 and 3, a simple static AtomicInteger and log statement would work:

    public class AutoAssignTask extends AbstractDirectoryMonitor {
    
        private static final AtomicInteger instances = new AtomicInteger();
    
        @PostConstruct
        public void init() {
            System.out.println("AutoAssignTask instance "+instances.incrementAndGet());
            //....
        }
    }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems like many people have some issues once they start adding video into
I have some utility methods that use Microsoft.Web.Administration.ServerManager that I've been having some issues
I have some issues with .load : My site use this line of code
I want to use eclipse for Arduino development and I have some issues. I
We have some issues in our application with skype taking over some of our
I have some issues with a PHP file that is not working properly. The
I'm have some issues adding a class to 2 navigation links on a theme.
I seems to have some issues in order to compile gproc from uwiger. I
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
I am integrating PayPal in my website But I have some issues in it.

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.