Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
    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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Cache Update in Async Thread-- Can this fit in Observer pattern ?  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have a use-case where as soon as my API receive a request, then i need to make a call to some remote server to fetch the data as per id received in the request, run my processing on that data and populate a response value-object.
Now i need to do two things:
1) return this response value-object to the caller of my API which completes this flow in the same thread,
2) Also start an Async thread to update this response value-object(which is JSON)  in Stringify manner to a cache . This second flow is of the style "fire and forget". Here I am planning to use observer pattern in second flow ( the Async one).So that means as soon the response value-object is formed, it will call the setValue(..) method of the OBSERVABLE class which will call its OBSERVER, and in the OBSERVER's Update() method i will start a new thread which will update the cache.

But someone was saying using observer here i am increasing the time of processing, but i feel using observer-pattern provides loose coupling and code-extandability. Do you feel the same that by using Observer pattern here i am increasing time of processing, if that is the case then i can start this new thread for Async processing in my API itself and not using Observer class to do that.
Lets me know your thoughts at your earliest so i can take it further.
 
Sheriff
Posts: 13176
219
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post the same message to multiple forums. Locking this topic. Continue discussion here: https://coderanch.com/t/703437/engineering/Observer-Design-Pattern-case-good
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!