Thread-safety of SqlSession
Two main implementation of SqlSession
interface have opposite semantics in thread-safety.
org.apache.ibatis.session.defaults.DefaultSqlSession
is not thread-safe and so should not be shared among threads. But, org.mybatis.spring.SqlSessionTemplate
provided to used with Spring
framework is thread-safe.
Two implementations can not replace each other. So, the POJO into which SqlSessionTemplate is expected to be injected by Spring IoC container will not work correctly with other implementation of SqlSession
in non-Spring environment. Can this be called POJO ?
I think this is somewhat confusing feature. I'm not sure thead-safety is dealt with interface scope of respective implmentation scope. SqlSession
is in the heart of MyBatis
, and so it seems desirable to have more clear semantics.
1 comments:
Excellent post. I am grateful to you for explaining this complex concept in such an easy and simple way. This article is the best guide I have read so far regarding it.
Post a Comment