• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with caching of information by thread/Hashmap? Not sure  RSS feed

 
shoeb sattar
Greenhorn
Posts: 14
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
We have a batch program which is schedule to execute twice during a day.
This batch program creates more than one file depending on some condition.
We store this condition in a hash map as a key and and file name as value.
The file name is a time-stamp with multiple file names separated by 10 milliseconds.The file name creation uses following code snippet



Problem is when the program is executed for 2nd time it even 3rd or 4th  time it is creating file with time stamp 2 days older.

For example if I run the program today i.e. 14th Sep 2016 it is creating file name with time stamp of 12th SEP 2016.

Is the hash-map caching the data and not getting cleared during next run?

Sample file name :MX-222-01-20160912225702912-1.xml

 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the scope of the variable date?  Is it an instance variable?
 
shoeb sattar
Greenhorn
Posts: 14
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:What is the scope of the variable date?  Is it an instance variable?

Hi Knute, Thanks for response.
The date is declared as follows:
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using Calendar rather than System.currentTimeMillis? I presume you are on an older version of Java® and cannot use the newer date time packages. Unless our files are very large, do you really take as long as 10ms to read them?

I shall move this discussion as too difficult for this forum.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is that Date reference static?
 
shoeb sattar
Greenhorn
Posts: 14
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Why is that Date reference static?

Unfortunately I am one of those who have to maintain other people's code.
I assume its static because we wanted to have same file names separated by 10 ms for one instance of execution.
MX-222-01-20160912225702912-1.xml
MX-222-01-20160912225702902-1.xml
MX-222-01-20160912225702892-1.xml
MX-222-01-20160912225702882-1.xml
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me it shouldn't be too hard to add a line of code which runs when the program starts and writes the value of that Date object to the log. Just make sure it actually runs when the program starts.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!