MyBatis - Pooling of SqlSession

78 views
Skip to first unread message

Nitesh Soni

unread,
May 13, 2021, 2:34:19 PM5/13/21
to mybatis-user
Hi,
I am using MyBatis3.5.6 in our application to interact with SQL DB. Whenever a DB call is required 'SqlSessionFactory.openSession()', This provides me a new SqlSession. This SqlSession, I use to execute my DB calls. 
My worry is, At peak hours it may create large number of session and could make my system unResponsive. Is there any way, by which I can pool the sessions or limit the number of sessions?

Regards,
Nitesh 

M Huzaifah

unread,
May 14, 2021, 4:59:32 AM5/14/21
to mybati...@googlegroups.com
Dear Nitest,

you should use Spring, use MyBatis-spring to integrate with. in spring configuration you can do what you want like pooling, security, etc
let spring care your connection.

regards

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/89a38307-3108-44c7-869f-cb3519eb58a6n%40googlegroups.com.

Jose María Zaragoza

unread,
May 14, 2021, 9:59:35 AM5/14/21
to mybati...@googlegroups.com
Hi:

Why dont you close every SqlSession opened ?

Regards

Nitesh Soni

unread,
May 14, 2021, 11:30:42 AM5/14/21
to mybati...@googlegroups.com
Dear Huzaifah,
Thanks for your reply, Is it possible to configure the size of pool?

Regards,
Nitesh


You received this message because you are subscribed to a topic in the Google Groups "mybatis-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mybatis-user/ItvUciF9c-c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/2A9691A7-27E1-4190-83EB-E68978E4B42B%40gmail.com.

Guy Rouillier

unread,
May 14, 2021, 2:56:29 PM5/14/21
to mybati...@googlegroups.com
Nitesh, take a look at the MyBatis User's Guide, specifically section 3.1.8 Environments.  You don't need Spring to obtain a pooled connection, although if you are already using Spring, you have that option, as Huzaifah points out.  Using a pooled datasource, you can specify poolMaximumActiveConnections, poolMaximumIdleConnections, and several other options.  

You don't mention your operating environment for your application.  Depending on that, you may have better alternatives.  For example, if you are implementing a web application and you are using an application server such as Tomcat, those servers already have provisions for pooled data sources, and you are better off using those facilities.

--
Guy Rouillier
Reply all
Reply to author
Forward
0 new messages