• 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

Connection Pool/servlet

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Servlet /JDBC experts,
I need some urgent help regarding ConnectionPool .
I have created connection pool of max 15 connections in init()method of servlet.
I am creating a connection object from the pool and passing that object to a class trhough its constructor .This class uses the connection object and fetches the data and returns the same trhu a string object to the main servlet.
Problem here is that the connection used by another class is not getting released thru the'release connection' method of connectionpool trhu finally clause in the main servlet.Connections are stopped after 15 connections.
Can anyone help me for the saem.
public class servlet {
init(){connectionpool}
doget{
connection con=conpool.get....
someclass class=new someclass(con);
String r=class.str();
p.println(r)
}
finally(!con=null){conpool.releaseconnection)
}//doget over
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this connection pooling. It is ready to use type and very effective...
Download the source code from
http://www.mcp.com/isbn/sourcecode/0672316005/source.exe
and then find the connection pooling.

Originally posted by mani dalal:
Hello Servlet /JDBC experts,
I need some urgent help regarding ConnectionPool .
I have created connection pool of max 15 connections in init()method of servlet.
I am creating a connection object from the pool and passing that object to a class trhough its constructor .This class uses the connection object and fetches the data and returns the same trhu a string object to the main servlet.
Problem here is that the connection used by another class is not getting released thru the'release connection' method of connectionpool trhu finally clause in the main servlet.Connections are stopped after 15 connections.
Can anyone help me for the saem.
public class servlet {
init(){connectionpool}
doget{
connection con=conpool.get....
someclass class=new someclass(con);
String r=class.str();
p.println(r)
}
finally(!con=null){conpool.releaseconnection)
}//doget over



------------------
Vikas Aggarwal
Technology Associate
http://www.vikinsa.com
 
mani dalal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Vikas,
Thanks for the link.It helped me a lot.I still have one question.Suppose I ahve more than one servlets in an application , each one of them wants to retrieve and psot data to DATABASE, do I need to instantiate use separate connection pool in the init method of each servlet.
OR can I use a single connection pool for all the servlet.If it is so, how do I pass the connection object created by a single connection pool instantiated in one servlet on on-load feature of web.xml of TOMCAT?
Please help me solve this.Also , explain me, in practical applications , how con pool is used?
Thanks,
Mani
 
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, you can use one connection pool for the entire application if the application only uses that one database. You can do it by storing the connection pool in the ServletContext object the first time the pool is created.
Connection pool is used to save resources by better controlling connections made to db.
 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I am confused about is if whether each Connection should be a Thread. From the books I read, Connections in connection pool do not implment Runnable or Thread, but the more I think about it, the more I think each Connection should be a Thread.
Can anyone please help?
 
If you're gonna buy things, buy this thing and I get a fat kickback:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic