multithreading - Java Multithreaded Transactional service layer -
i have task in have implement transactional service layer manages multiple daos (those daos have crud operations). in order insert database have use multiple daos, need start transaction.
i implemented daomanager class implements singleton pattern. class has methods getnewsdao() return instance of dao. can daomanager , dao classes have single instance per program.
i implemented connectionmanager class has 2 fields - connection pool (used retrieving connection) , connection field.
basically, when call service layer method flow like:
- get connection connection pool , set connection field inside connection manager
- call dao methods , pass them connection field connectionmanager method parameter
every service class has daomanager field - singleton , connectionmanager field - connectionmanager not singleton. has instance per service class instance.
the problem comes when multiple threads use service classes. a transaction made single thread have make sure same connection not shared among threads.
should move daomanager , connectionmanager in thread local , make connectionmanager singleton? single instance of daomanager , conenctionmanager per thread , change passing connection method in dao setting in instance field of dao?
or design practice?
Comments
Post a Comment