0

In my application there are some data which always reads from Seq. I am thinking of having a data structure which would start getting loaded with DB Seq and whenever I need DB Seq, I can directly read from there. Once the data is read from there it needs to be removed so that no one else can read the same data again. Also this data structure would automatically hit DB and get more seq objects once it is left with only 0.25 % of total capacity something like HashMap.

This would enable to not hit DB when I need but directly read from this structure and save DB hit time in my flow.

I am thinking of maintaining a Stack kind of structure but how to reload it automatically because if I use some kind of Scheduler I am not sure how to configure it appropriately.

Any help would be great.

djyo02
  • 27
  • 1
  • 11

1 Answers1

0

Lets, consider below example

Step 1 : You can create stack of size 16 and push 16 sequence which is loaded from DB sequence.

Step 2 : check size of stack while poping/removing elements from it. if it is 4, then again loads sequence from db if not leave it.

lion_pankaj
  • 160
  • 1
  • 12
  • Thanks for the answer. Actually this flow would be used in Multi threaded environment and if I maintain a synchronized operation on Stack then it would not solve the problem of reducing the overall time. I would accept the answer as it surely solves the mentioned issue. – djyo02 Feb 09 '20 at 12:24