• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

static methods and EJB

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can business methods in EJB be declared static?? In not , can anybody please tell the reason
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, because the spec prohibits it. Read Section 7.10.4 in the EJB 2.0 spec, where it states in the requirements of business methods "the method must not be declared final or static".
Kyle
 
Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is what I want to understand. A stateless session bean can have static methods, what is the problem in having so
can the methods in EJB call other class methods which are static?
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Business methods are declared in component interfaces. You cannot have static methods in an interface.
If methods in stateless session beans are static then the instance variable must be static as well and this will create synchronization problems when there are several instances of the bean.
Static methods cannot be overridden but only hidden. The conatiner specific class usually overrides your bean class to provide container services which cannot be done if your business methods are static(since the superclass method is hidden and not overridden).
You can have non business methods as static but it is of no use.
 
Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can the bean methods call other static methods of a class??
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Monmohan Singh:
can the bean methods call other static methods of a class??


Yes it can provided those static methods are not business methods. Why do you want the methods to be static.
[ December 06, 2003: Message edited by: Pradeep Bhat ]
 
Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well the problem is from a session bean we are calling static method of a third party work router API and are facing constant database deadlock problems.
I wanted to know if this could be a possible reason
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup. Given that there will always be multiple threads running throug the EJB's, then this certainly sounds like a plausible reason for deadlock.
Kyle
 
Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what could be a possible workaround on this given the constraint that we need to use the work router API
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, synchronization won't work if you are deploying this application into a cluster -- you'll still get the database deadlock across JVMs. It seems to me that the only way to solve this is to open a trouble ticket with the vendor of your third-party router software and make it THEIR problem (which it is!).
Kyle
 
reply
    Bookmark Topic Watch Topic
  • New Topic