Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling init or destroy.  RSS feed

 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
Can I call a init() method from service,
destroy from init()
destroy from service().........
like that all permutations ?

I found no use in that, but in an interview, the interviewer ask me that is there any restrictions in that. is Any restriction in specification or any other restrictions?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
they are just methods, sure you can call them.
As you say, it would serve no real purpose but you could do it.
 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, Dave thanks,
But is there any restrictions in specification?
I just checked but not found any information that, you can do or you
can't do.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jose Mon:
But is there any restrictions in specification?


Refer to this.. article by Budi Kurniawan

hope it make you more clear on that..
 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I already know the flow.
But want to know that any restrictions is given?
An interviewer ask me this.
Also asked, is it legal?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet code never calls the lifecycle methods - the servlet container does that.
 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
Do all lifecycle or callback methods are like this.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, the servlet lifecycle calls this.
Methods like these are designed to say "the container is going to do something, here's your chance to do something at the same time if you want".

It's handy to be able to set up resources when the servlet is created and remove them when the servlet is destroyed, so the lifecycle methods give you a place to tap into this.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jose Mon:
I already know the flow.
But want to know that any restrictions is given?
An interviewer ask me this.
Also asked, is it legal?


hope you'll understand why i suggested you that article.. that cover your subject line in details with more clear picture..
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's the conclusion guys?? Can we do it or is it left to the container??
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do it, in the same way that you can hit yourself in the middle of the forehead with a ballpeen hammer.

Both actions make the same amount of sense.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!