hoyacom / log4jdbc-log4j2

Automatically exported from code.google.com/p/log4jdbc-log4j2
0 stars 0 forks source link

Db2RdbmsSpecifics implementation is not thread-safe #23

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Probably,Db2RdbmsSpecifics implementation is not thread-safe. 
Because SimpleDateFormat is not thread-safe...

public class Db2RdbmsSpecifics extends RdbmsSpecifics {

        private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
                        "'TIMESTAMP('''yyyy-MM-dd HH:mm:ss.SSS''')'");

        public Db2RdbmsSpecifics() {
                super();
        }

        @Override
        public String formatParameterObject(Object object) {
                if (object instanceof Date) {
                        return DATE_FORMAT.format((Date) object);
                } 
                return super.formatParameterObject(object);
        }
}

Original issue reported on code.google.com by kazuki43zoo on 4 Oct 2014 at 1:22

GoogleCodeExporter commented 8 years ago
Just to save me some search, is RdbmsSpecifics thread-safe? (meaning, the 
problem only comes from the DATE_FORMAT attribute, not from the returned 
SimpleDataFormat)?

Original comment by frederic...@gmail.com on 6 Oct 2014 at 11:49

GoogleCodeExporter commented 8 years ago
RdbmsSpecifics is thread safe because create instance of SimpleDateFormat per 
method call.
SimpleDateFormat method is not supported execution under the multithreaded 
environment.(http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat
.html#synchronization)

I does not good at English,  is ok with this answer ?

Original comment by kazuki43zoo on 6 Oct 2014 at 12:20

GoogleCodeExporter commented 8 years ago
As one cases, FastDateFormat(Common-lang) & Joda-Time is thread-safe libraries.

Original comment by kazuki43zoo on 6 Oct 2014 at 12:36

GoogleCodeExporter commented 8 years ago
Yes, of course, thanks, I will fix this quickly. 

Original comment by frederic...@gmail.com on 7 Oct 2014 at 4:06

GoogleCodeExporter commented 8 years ago

Original comment by frederic...@gmail.com on 31 Jan 2015 at 11:10