Hibernate c3p0 ThreadPoolExecutor pooling, am I doing this right?

I use hibernate and c3p0 for the database, and I have a Java application with ThreadPoolExecutor. What I do, I present various hibernate-related tasks for storing data using Hibernate using transactions and getCurrentSession. So i

new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.MINUTES,taskQueue); Runnable { @Override public void run() { Session session = HibernateDAO.getInstance().getCurrentSession(); Transaction tx = null; try {tx = session.beginTransaction(); ..... } 

And hibernate.cfg thread org.hibernate.connection.C3P0ConnectionProvider 1

  <!-- Database c3p0 settings --> <property name="hibernate.c3p0.min_size">3</property> <property name="hibernate.c3p0.max_size">3</property> <property name="hibernate.c3p0.initialPoolSize">3</property> <property name="hibernate.c3p0.max_statements">100</property> <property name="hibernate.c3p0.timeout">5000</property> <property name="hibernate.c3p0.acquire_increment">2</property> 

My goal is to get the stream from the artist, get the connection using getCurrentSession and execute session.saveOrUpdate (item). Now I have a couple of questions. What level of isolation should I use because I have 95% write / update and 5% read and read not interrupted by writing. I hit the HTML log from log4j

 905 pool-1-thread-1 DEBUG com.mchange.v2.resourcepool.BasicResourcePool trace com.mchange.v2.resourcepool.BasicResourcePool@434cb775 [managed: 3, unused: 0, excluded: 0] (eg com.mchange.v2.c3p0.impl.NewPooledConnection@697506e6 ) 905 pool-1-thread-5 DEBUG com.mchange.v2.resourcepool.BasicResourcePool trace com.mchange.v2.resourcepool.BasicResourcePool@434cb775 [managed: 3, unused: 0, excluded: 0] (eg com.mchange.v2.c3p0.impl.NewPooledConnection@697506e6 ) 965 pool-1-thread-4 DEBUG com.mchange.v2.resourcepool.BasicResourcePool trace com.mchange.v2.resourcepool.BasicResourcePool@434cb775 [managed: 3, unused: 0, excluded: 0] (eg com.mchange.v2.c3p0.impl.NewPooledConnection@697506e6 ) 

Does this mean that I have only 1 connection in c3p0 or several connections in the same pool?

AM I USE THAT IT SHOULD BE USED

What isolation level is best suited for simultaneous recording?

thank everyone in advance if someone needs more data and explanations, just poke.

- EDIT: answers

As suggested from answerd, I checked the mysql server administrator, and there are more connections that are used to query .. so this is the CORRECT WAY to use it: D ... As for isolation levels, I try to allow

+4
source share
1 answer

This means that you have one pool with three initial connections. You should be able to confirm this by looking at your SQL server monitor.

Remember that your SQL Server configuration intercepts C3PO, so if you have multiple threads competing for transactions in the same table, you may find that your write and update operations are blocked regardless of your pool configuration.

You may find that batch insertion / updates within a single transaction can provide better performance than moving them to separate threads. This article is interesting.

As for determining the isolation level, I understand that this is more a matter of read performance than write. I never found myself in a situation where I would need less than READ COMMITTED , since allowing dirty reads with READ UNCOMMITTED completely destroys the benefits of using the ACID database in the first place. However, I am not an expert in this field, someone else may have a different opinion. If this really bothers you, I would compare both settings with the database of your choice to determine how much performance you can get, if any.

+1
source

Source: https://habr.com/ru/post/1399203/


All Articles