Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JAX-WS @PostConstruct annotation and database connection

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a web service that uses JNDI to get the postgres connection.

At present all the web methods get call a method that gets the connection, and then at the end of the method I close the connection.



Is it better to use a method that is annotated with a @PostConstruct, this method gets the connection from the pool?





Will this even work?

John.
 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to have a method with @PreDestroy where you can free the reference.

PostConstruct & PreDestroy are life cycle methods, occurs only once;
PostConstrutct - after instance is created (get the resources)
PreDestroy - before instance is destroyed (free the resources)

There is no need of following thread, but still I am posting it, as I found it interesting and you may also like it,
http://forums.java.net/jive/thread.jspa?threadID=34434

thanks...
 
John Blunket
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Deepika,

When you say life cyle events, is this the lifeCycle of a webMethod call?

As far as I know, since the web service is stateless, every time I call a method from the client, it should do a PostConstruct and then after the method has finished it should do a Pre-Destroy.

Is that correct?

John.
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I think you already asked this question, albeit in a slightly different form here: https://coderanch.com/t/466152/Web-Services/java/Glassfish-init-method
Please correct me if I am wrong.
Best wishes!
 
John Blunket
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ivan,
I think you are right.
I might just be going round the twist!!!

Thank you,
John.
 
Let's get him boys! We'll make him read this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic