This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source 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 ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

stateful Dao thread safety  RSS feed

 
Greenhorn
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
Ross





 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!