File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Application Frameworks and the fly likes stateful Dao thread safety Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "stateful Dao thread safety" Watch "stateful Dao thread safety" New topic

stateful Dao thread safety

ross Bertonoli

Joined: Apr 16, 2008
Posts: 6
Hi All;
A webservice operation have the following tasks :
1-calls dao operation1 and operation2 to create a row in table 1 and 2 with RowID1 and RowID2
2-do something else ( like calling another webservice2 )
3-if the webservice2 response satisfy a condition then call dao operation3 to create a row in table 3 with fk = RowID1) and second fk = RowID2

so somehow RowID1 and RowID2 has to be provided to DAO operation3.

I'm trying to find a way not to pass around RowID1 and RowID2 between higher level classes as these IDs really should not be known by the webservice operation 1 as they are not part of business logic.
option 1:
make DAO stateful inwhich RowID1 and RowID2 are class members and can be used by dao operation 3.
for thread safety concern use spring scope (request) so that all the class members only belong to one request/thread in order to avoid the following threading issue:
request1 ->
call to dao method to create RowID1 and RowID2 a car, and store them in class members
then webservice operation does other tasks which as calling webservice2 which takes a long time to complete
meanwhile request2 comes in ->
call to dao method to create RowID1 and RowID2 a car, and store it in class members. ( without thread-safety the request2 will override the request1 RowID1 and RowID2 )
WS op does other tasks
request1 continues ->
based on a condition call dao operation 3 to create a row in table 3 with fk = table1 RowID1) and second fk = RowID2

option 2:
dao to pass the RowID1 and RowID2 and pass it as input to dao operation 3

really appreciate your comment and other suggestions

I agree. Here's the link:
subject: stateful Dao thread safety
It's not a secret anymore!