Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

stateful Dao thread safety

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Happily living in the valley of the dried frogs with a few tiny ads.
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!