Raffaele
Raffaele

Reputation: 511

Avoid memory leak ThreadLocal SimpleDateFormat

I'm working with jdk7 on weblogic 11g, as I would to use ThreadLocal variable to overcome issues with SimpleDateFormat and thread safety, I also thought about potential memory leak, in case I don't remove the current value. In order to do that, I'm wondering if it's ok to add to the constructor of the object in witch I'm using this ThreadLocal (static final) instance the following lines

Runtime runtime = Runtime.getRuntime();
        runtime.addShutdownHook(new Thread(){
            @Override
            public void run() {
                dateFormat.remove();
            }
        });

or if it would be better placed in a static block (or if there is any better solution)

Upvotes: 0

Views: 322

Answers (0)

Related Questions