Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

static methods and EJB  RSS feed

 
Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can business methods in EJB be declared static?? In not , can anybody please tell the reason
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
can the bean methods call other static methods of a class??
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • 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
  • 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
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!