.I have developed a java Application that downloads html from specified urls.I am able to download in multithreads .But now i want to use connection Pooling as well.I searched for various ways we can perform connection pooling but all are related to client server applications (using apache, Tomcat etc). But I need this on my single machine only.Here i just want to download html and insert into Mysql database in threads. How can I do that.
-
Static (singleton) BoneCP instance. jolbox.com Or write your own! Static synchronized collection with synchronized methods will do it.jn1kk– jn1kk2013-05-28 14:04:54 +00:00Commented May 28, 2013 at 14:04
-
do i need to create multiple instances of connection for synchronized collection ?tagneha– tagneha2013-05-28 14:10:43 +00:00Commented May 28, 2013 at 14:10
-
Not sure what you are trying to ask. But yeah, if you want to use more than one connection for all threads, you need to create more than one connection (still for a single pool). Usually, you start with a hardcoded minimum, something like 3. And always check not to exceed the maximum, anywhere from 5-15.jn1kk– jn1kk2013-05-28 14:14:22 +00:00Commented May 28, 2013 at 14:14
-
also refer to the concept JNDI connection : docs.oracle.com/javase/jndi/tutorial/ldap/connect/pool.html and also : docs.oracle.com/javase/jndi/tutorial/getStarted/overviewHussain Akhtar Wahid 'Ghouri'– Hussain Akhtar Wahid 'Ghouri'2013-05-28 14:15:06 +00:00Commented May 28, 2013 at 14:15
-
1@Tagneha, you make a class. You put a static synchronized collection in that class. Then you make an instance deposit method which deposits a connection into the pool, and then an instance get method which gets a connection from the pool. Both methods need to be synchronized. The get method should check the size of the pool, if it is empty, make a new connection and immediately return it. If pool is not empty, remove it from the pool (or mark it as used) and return (make sure you check your max connection limit).jn1kk– jn1kk2013-05-28 14:21:34 +00:00Commented May 28, 2013 at 14:21
|
Show 2 more comments
2 Answers
take a look at JNDI connection refer this and thislink
the basic concept of JNDI is to deal with connection pooling
where you create a pool of database connections and reuse the already existing connections
1 Comment
Mark Rotteveel
Please reformat your answer so it isn't formatted as code, and add the links.