• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

stateful Dao thread safety

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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





 
Beauty is in the eye of the tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic