4

.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.

7
  • Static (singleton) BoneCP instance. jolbox.com Or write your own! Static synchronized collection with synchronized methods will do it. Commented May 28, 2013 at 14:04
  • do i need to create multiple instances of connection for synchronized collection ? Commented 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. Commented 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/overview Commented 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). Commented May 28, 2013 at 14:21

2 Answers 2

1

You can either use BoneCP, C3P0 or DBCP to give you a few to look at. Each have their own advantages and disadvantages so it's up to you to choose which is best for your situation.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Please reformat your answer so it isn't formatted as code, and add the links.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.