C3P0 maxpoolsize configuration under Multi-threading

Source: Internet
Author: User

ETL tools completed almost, today, encountered a problem, is to C3p0 configured maxpoolsize for 10, the purpose is to let the entire application at the same time to obtain the maximum number of connection is 10, but after testing this part of the application, There are far more than 10 links found on the PostgreSQL side. Because the tool is multi-threaded, so I think, is not a multi-threaded problem, check the number of connection, it is indeed the number of 10* threads. Then a test was made:

To configure Maxpoolsize to 5, run the following program:

Combopooleddatasource CPDs = new Combopooleddatasource ("Postgres"); for (int i = 0; i <; i++) {cpds.getconnection ();} Combopooleddatasource cpds2 = new Combopooleddatasource ("Postgres"); for (int i = 0; i <; i++) {cpds2.getconnection () ;}

Maxpoolsize configured to 5, altogether want to obtain 20 links, at this time to see the server side of the PostgreSQL connection number is 5, the official expected results.

Under Run the following program:

for (int i = 0; i < 2; i++) {New Thread (new Runnable () {@Overridepublic void run () {Combopooleddatasource CPDs = new Co Mbopooleddatasource ("Postgres"); for (int i = 0; i <; i++) {try {cpds.getconnection ();} catch (SQLException e) {E.pri Ntstacktrace ();}} try {thread.sleep (100000);} catch (Interruptedexception e) {e.printstacktrace ();}}}, "Thread" + i). Start ();

Two threads, each thread wants to get 10 links, the number of links on the PostgreSQL server side is 10. Change I<2 to I<3, run once, see the number of connections on the PostgreSQL server side is 15, you can determine

PostgreSQL server-side connection number =maxpoolsize*numthread;

The underlying reason is probably because C3P0 is not designed for multithreading, and the underlying JDBC is not thread-safe. Specific reasons, there are opportunities in specific analysis.






C3P0 maxpoolsize configuration under Multi-threading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.