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 9164879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:47:14+00:00 2026-06-17T14:47:14+00:00

I have to implement a simple Timer task for following scenario – method1(){ …..

  • 0

I have to implement a simple Timer task for following scenario –

method1(){  
.....  
   if(success){  
      trigger method2 for next 30 min every 15 sec  
   }  
}

I have implemented this code using java.util.Timer and java.util.TimerTask and its working fine. However, my code will eventually be deployed as a web service in glassfish server. So I want to know will it create any problems due to glassfish container as I am indirectly using threads via Timer.

I am also not sure whether I should EJB Timer Bean. Can somebody please advise what are the pros and cons of both the approaches?

  • 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-17T14:47:16+00:00Added an answer on June 17, 2026 at 2:47 pm

    As with most everything EJB, the biggest distinction between the two techniques is transactions. Timer EJBs are, well, EJBs, so each invocation will be a unique transaction, and the container will manage all of those details for you.

    The thread, especially if created from within an EJB, will have an undetermined transactional state. Most containers associate a lot of context with the currently executing thread, especially transactional state, this is one reason (among others) that self made threads are a bad idea in an EJB container — the containers context information can be missing or corrupted.

    For an EJB Timer, you can readily create one that that fires every 15s, but you will need to keep track and cancel it manually after 30 minutes. You could use a ScheduleExpression to express the “every 15s for 30m” rule, but you’ll still need to cancel the timer at the end (and it would frankly be more work to create that expression properly). It’s easier to just put a start time in the Timers Info that tells it when it started, then it can terminate itself on the last run.

    In the days before Java EE 6, Timers were persistent and survived container restarts (though NOT application redeploys). Now, the persistence is optional, so you’ll need to pay attention to that detail.

    If this method were to be triggered from the Web tier (and not the EJB tier), the threading restrictions are relaxed, or you could use the Quartz Timer.

    But the EJB timers are pretty good, and better for Java EE 6. I would use the EJB Timer, but I’m comfortable with them and have worked with the harder-to-use pre-Java EE 6 ones for some time. If you’re in the EJB tier for this whole process, I would certainly use them.

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

Sidebar

Related Questions

I have to implement simple ray tracing algorithm, but I can not figure out
I am trying to implement a simple subscribe button using Paypal. I have used
Is there any example on how to implement a simple login page/dialog? I have
i have this class called MemoryManager, it is supposed to implement a simple smart
I have a requirement which sounds like kind of simple but hard to implement
I have the following class (from a simple Spring tutorial) public class CarValidator implements
our task is quite simple, we have an object graph where each object (IDItem)
I have implemented a simple clock like so: - (void)runTimer { timer = [NSTimer
I have a simple Azure Worker role running that performs a task every day
I have to implement a simple onscreen keyboard, where the user has to first

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.