On Wed, Oct 3, 2012 at 7:57 AM, Prabu Uthirapathi <u.p...@gmail.com> wrote:
Hi,
I am working on mybats3.0+spring 3.0. I am working on spring services. spring service has a dependency on MyBatis mapper class. I would like to know whether MyBatis3.0 mapper is thread safe.
Duc Trung TRAN
unread,
Oct 3, 2012, 11:34:58 AM10/3/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mybati...@googlegroups.com
Hello,
The mapped statements build up is not thread safe. In our project, we had to preload all statements when building sqlSessionFactory. But it was more than 1 year ago. The problem could be fixed since then.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mybati...@googlegroups.com
For example:
public class SpringServiceImpl implements SpringService
{
@Autowired
UserMapper userMapper;
}
Is userMapper thread safe (I am using spring-mybatis)?
Eduardo Macarron
unread,
Oct 5, 2012, 10:24:24 AM10/5/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mybati...@googlegroups.com
yes, it is.
Duc Trung TRAN
unread,
Oct 5, 2012, 12:03:45 PM10/5/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mybati...@googlegroups.com
I don't know how UserMapper is implemented but i suppose it use sqlSession internally. In this case it is not thread safe when mapped statements are not loaded. You can test by creating some threads which concurrently execute the same method in UserMapper. There will be exceptions raised.
But once the mapped statement is loaded, it's thread safe.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mybati...@googlegroups.com
Eduardo,
Yes, I've been using SqlSessionTemplate And it does not work. The thread safety problem is from within Configuration class of Ibatis which is used by SqlSession.
It's possible that i did not use spring mybatis api correctly. But can you first try to do some tests as I suggest?
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mybati...@googlegroups.com
BTW the spring application context will not be started until all mapped statements are loaded. That loading process is not thread safe and it is expected to be done by the startup thread.
If you are loading mappers lazily, thread safety problems may arise. Not sure about that.