0

On refreshing the page for second time or hitting the link after first execution brings the same object instance output. I couldn't see the method executing for next time and bring new output value. It brings the old value itself

I am doing some database query execution in this method.

When I print the execution time changes for first 2 refresh of page and after tat it remains same for remaining access to that page.

I tried to print the System.currentTimeMillis() then it too didn't get updated on every refresh it was showing the same timestamp. Why is my method not executing after 2 refreshes ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Pradeesh
  • 1
  • 1
  • 1
    Seems like your browser is caching the page, check out about how to force your browse to not cache that specific page; there are lots of questions about that here. – SJuan76 Oct 20 '16 at 10:53
  • Possible duplicate of [Making sure a web page is not cached, across all browsers](http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers) – AxelH Oct 20 '16 at 11:12
  • yes it was what i checked first i tried by clearing cache too. – Pradeesh Oct 20 '16 at 11:16
  • Tried to hit the link from another browser and another machine also then also getting the same result – Pradeesh Oct 20 '16 at 11:17
  • do you have some kind of server-side caching? – developerwjk Oct 21 '16 at 21:18

1 Answers1

0

The issue was fixed. I was storing the output of method to a variable and it was translated to a instance variable on the generated servlet code. When the servlet is created, this value will be assigned in the constructor. And as we do not have control of the servlet life cycle, we have no guarantee that the servlet is re-created for each request.

Pradeesh
  • 1
  • 1