[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 886
  • Last Modified:

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

0
rama_krishna580
Asked:
rama_krishna580
  • 5
  • 4
  • 4
2 Solutions
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now