Java hashmaps and memory leaks -


i have console java application needs data database. application running constantly, every 30 seconds, in order lower strain on db i'm using sort of cache data.

because there isn't large amount of needed data in database, i'm using singleton hashmap cache. cache class looks this:

public class cache extends hashmap<integer, hashmap<integer, arraylist<string>> { //some code } 

every 5 minutes system refresh cache by:

1) calling "clear()" existing data 2) filling cache new data db.

tell me, if call "clear()" structure have ("nested" hashmaps) java clear data containd under cache keys, or i'll end memory leaks?

you can this, suggest better alternative replace it. more efficient if have multiple threads.

public class cache {      private map<integer, map<integer, list<string>>> map;       public cache(args) {      }       public synchronized map<integer, map<integer, list<string>>> getmap() {           return map;      }       // called thread every 30 seconds.      public void updatecache() {           map<integer, map<integer, list<string>>> newmap = ...           // build new map, can take seconds.            // swap in new map.           synchronzied(this) {               map = newmap;           }      } } 

this both thread safe , has minimum of impact.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -