This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
    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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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: 12825
211
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
 
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!