Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Fundamental Doubt about static methods

 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there Ranchers !

My mind is broken, I feel I can't access the entirety of my knowledge on EJB 3(or otherwise I need more practice). I wish I could be helped with the following question(s)..

Is it valid to have static methods in an EJB 3 class ?

I wanted to know especially if there's a problem with having static methods that are marked with life-cycle annotations like @PostConstruct.

Would I happen to obtain the same results given a Session Bean or a Message Driven Bean ?

That'd be it for now,

Thanks in advance,

Jose

 
R K Singh
Ranch Hand
Posts: 5388
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont know about EJB3 but in EJB2.x and in general also, it does not seem to be good practice to have Static methods in Remote class.
You will not be able to access it remotely.
 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello !

I think I may need to know more. you see, I'd like to know what's the meaning of this 'bad practice' when I use annotations especially.

Is it valid at all?

All clarifications are appreciated.

Jose
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use of annotations doesn't change the fundamentals. It doesn't make any sense to use static methods in an EJB. The container is going to call all methods as instance methods anyway. I would go further to argue that static methods in any code (outside of statup code) in an EJB application is bad practice. Static methods will limit the ability to scale the application and increase the risk of something turning up that is not threadsafe.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to know especially if there's a problem with having static methods that are marked with life-cycle annotations like @PostConstruct.


@PostConstruct is a lifecycle callback method. As per the EJB3 spec (section 12.4):

EJB3 Spec, Section 12.4 wrote:Lifecycle callback interceptor methods can have public, private, protected, or package level access. A lifecycle callback interceptor method must not be declared as final or static.
 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh !

This is so cool. I had a vague idea about why I shouldn't mark EJB business methods or Lyfecycle methods as static. Now I have a clearer picture, for that I must say Thanks.
I feel I need to ask about something that was stated by Jaikiran Pai....

"A lifecycle callback interceptor method must not be declared as final or static"


However the compiler won't stop me if I mark them as static, why is this ?

Is this a case of: "Just because you can do it, doesn't mean it's right" ?

That's a final thought I wanted to share... I'll be expecting your comments,

As always thank you very much !

Jose
 
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!