What are the required C3P0 settings for hibernate in order to avoid Deadlocks

后端 未结 6 1417
梦毁少年i
梦毁少年i 2020-12-07 11:36

I use Hibernate together with MySQL 5.1.30.

I have the next libraries:

  • c3p0-0.0.1.2.jar
  • mysql-connector-java-5.0.3
6条回答
  •  暖寄归人
    2020-12-07 12:06

    There is no definitive answer to this question, as it changes from application to application depending on the usage & load pattern.

    First point is refer the link https://www.hibernate.org/214.html, since it seems you've done that and gone ahead. here are a few tips;

    • numHelperThreads : Helper threads that don't hold contended locks. Spreading these operations over multiple threads
    • maxStatements : The size of c3p0's global PreparedStatement cache.
    • maxStatementsPerConnection : The number of PreparedStatements c3p0 will cache for a single pooled Connection.
    • maxAdministrativeTaskTime : Parameter that force a call to the task thread's interrupt() method if a task exceeds a set time limit

    First three parameter can improve or reduce the performance based on the value set where as forth parameter can interrupt the thread after set limit and give a change to run to other thread.

    Approximate values

    • numHelperThreads = 6
    • maxStatements =100
    • maxStatementsPerConnection = 12
    • maxAdministrativeTaskTime = need to sufficient time so that heavy query can run on production

    maxStatements and maxStatementsPerConnection should be tested for few months as few posting point to dead lock because of these parameter.

    Also referring to these links will be useful;

    • http://www.mchange.com/projects/c3p0/index.html#configuration_properties
    • http://www.mchange.com/projects/c3p0/index.html#hibernate-specific

提交回复
热议问题