public void cancelTimer(String timerName) in EJB Timer Service

Hi Experts,

I have some problem with TimerService EJB 2.1. i am getting an small error ....

And in my classpath i have included j2ee.jar which contains Timerservice..but when i am trying to build it, it is saying
sessionContext.getTimerService(); not found...code is like this...

i have declared sessionContext everything ....but what could be the problem....its a bit urgent..

      public void cancelTimer(String timerName)
      {
            try
            {
                                                // Here is the error it is saying....only this below line
                  TimerService ts = sessionContext.getTimerService();

                  Collection timers = ts.getTimers();
                  Iterator it = timers.iterator();
              
                  while (it.hasNext())
                  {
                        Timer myTimer = (Timer) it.next();
                        if ((myTimer.getInfo().equals(timerName)))
                        {
                              myTimer.cancel();
                              System.out.println("Successfully Cancelled " + timerName);
                        }
                  }
            }
            catch (Exception e)
            {
                  System.out.println("Exception after create timer : "+ e.toString());
            }
            return;
      }

awaiting for the answers...

R.K

LVL 23
rama_krishna580Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
> but when i am trying to build it, it is saying
> sessionContext.getTimerService(); not found...

Can you post the exact error message? Can you make sure ti contaisn the above class? hat happens if you do:

jar -tfv j2ee.jar | grep TimerService

0
objectsCommented:
where is sessionContext var declared?
0
objectsCommented:
It should implement the EJBContext interface.
Assuming it does try:

TimerService ts = ((EJBContext)sessionContext).getTimerService();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

rama_krishna580Author Commented:
Hi objects,

I have changed as per your suggestion, but still its giving error:
"The Method getTimerService() is undefined for the type EJBContext" ...
what could be the possible chances of this error here...

R.K
0
girionisCommented:
What specification of EJB are you using? I think the TimerService interface is only available from 2.1 version and above.
0
girionisCommented:
This is the j2ee 1.4 version with the EJBContext interface: http://java.sun.com/j2ee/1.4/docs/api/javax/ejb/EJBContext.html
0
rama_krishna580Author Commented:
I have already included J2EE1.4 j2ee.jar file in the classpath, and i tried with EJB 2.1 jar file also....but still the same error...?
any new thoughts.,.,,,? Still not solved......

R.K
0
objectsCommented:
are you sure the classpath that you changed is being used by whatever you are doing the build with?
0
rama_krishna580Author Commented:
Yes i am very sure...i have tried with both .jar files...but no change...

Any full example(s) available , so that i can compare with my application...if any thing can provide for me...

R.K
0
objectsCommented:
I don't think code examples will help, the code looks fine. The classloader is just not finding the class.
Perhaps there is a clash with your jar, check that you don't have any conflicting jars.
0
girionisCommented:
Can you check how many j2ee.jar files you have? Do a search on your computer.
0
rama_krishna580Author Commented:
Hi,

I am using Eclipse IDE 3.1,
so in this under the project classpath i have only one j2ee.jar ....

R.K
0
girionisCommented:
How many jars do you have in your classpath? Can you check that the *exact* class is not defined in any other ajr files before the j2ee.jar?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.