greptilian logo

IRC log for #friendlyjava, 2016-09-15

##friendlyjava on freenode

| Channels | #friendlyjava index | Today | | Search | Google Search | Plain-Text | plain, newest first | summary

All times shown according to UTC.

Time S Nick Message
07:43 aditsu_ joined ##friendlyjava
07:44 aditsu_ hi, would you recommend using ThreadLocal for SimpleDateFormat in a web application?
07:44 aditsu_ (to have a separate SimpleDateFormat per thread)
07:56 aditsu_ similar question for DecimalFormat..
08:12 aditsu_ hmm, ThreadLocal is not serializable
08:27 pulsar why would you need a threadlocal variable to be serializable? if i use tl in a webapp, i usually put the (de)init into a filter and make 10000% sure i do not forget to clear it after the request is done.
08:29 aditsu_ because I was thinking of making it non-static in a converter class, and the converter class has to be serializable; anyway, one option is to make the threadlocal static and hold a map
08:39 aditsu_ pulsar: something like this: http://dpaste.com/2RR8TP6
08:40 pulsar ic
08:43 pulsar just out of curiosity, why do you need the time/date/number formats to be TL? I am thinking @context and httpsession/headers/cookies in a similar helper class to determine the format associated with the request / user.
08:44 aditsu_ I'd like to reuse them (for performance reasons) and they are not thread safe
08:45 aditsu_ or do you think the performance impact is negligible?
08:45 pulsar pretty much. yeah.
08:46 aditsu_ if so, I could just create it on the spot in getDateFormat
08:46 pulsar if in doubt, i tend to go with the cacheloader from guava
08:46 pulsar keying will be an issue though, so you wont gain much
08:47 aditsu_ http://askldjd.com/2013/03/04/simpledateformat-is-slow/
08:48 aditsu_ actually, that doesn't really talk about the object creation
08:48 pulsar yeah, that what i was thinking.
08:49 pulsar depens on how often you need to format dates
08:49 pulsar and how it relates to the overall application
08:49 pulsar from my experience, dateformat will be the last of your concerns in a web application
08:50 pulsar and you could also cache the formatted strings by wrapping the df in a custom class with a TL cache or something
08:50 pulsar but all of that would fall into the pre-optimization category
08:50 pulsar 99% of the tiime it is a waste of latter.
08:52 aditsu_ this answer http://stackoverflow.com/a/22100487/179864 says "Creating an instance of SimpleDateFormat is very expensive" but it references the same link I posted above o_O
08:53 aditsu_ let me do a quick benchmark :p
08:54 pulsar i would make the benchrmark when you have something to compare order of magnitude of the numbers against
08:54 pulsar like db queries / persistence layer doing something
08:54 pulsar i still bet, that it will be a couple of orders of magnitude less significant than your persistence layer
08:57 aditsu_ I can create 50k SimpleDateFormat's and add them to a list in less than 0.5s, but 100k are taking around 2.5s for some reason :o
08:58 aditsu_ maybe gc kicking in or something?
08:58 aditsu_ anyway, sounds fast enough
09:03 pulsar yeah, you need to watch the gc spaces to understand the numbers. large number of objects does usually overflow the youngspace
09:03 pulsar java is pita for synthetic benchmarks usually.
09:04 pulsar and even non synthetic, chances are that some tweaks to the gc / memory ratios will give you a hunge performance boost are not that rare in a massive multithreaded application
09:28 aditsu_ oh great, I got my new fancy date converter ready and it's not using it for some reason :/
09:28 aditsu_ debug time..
09:31 aditsu_ ah, a matter of java.util.Date.class vs java.sql.Timestamp.class
12:03 Black-Ridder joined ##friendlyjava
12:03 Black-Ridder bonjour :)
12:04 Black-Ridder j'ai un petit pépin avec un code qui plante sous android studio http://pastebin.com/cdeU3b0F
12:04 Black-Ridder dès que j'appelle cette fonction l'application plante
14:40 aditsu 25 minutes..
15:46 pdurbin pardon my French
16:26 mr_lou joined ##friendlyjava
22:02 pdurbin_m joined ##friendlyjava
22:02 pdurbin_m Java EE Platform on Twitter: "New web site for JSON-B launched! #JavaEE8 https://t.co/E43ar51gHS": https://mobile.twitter.com/Java_EE/status/776094327592198144

| Channels | #friendlyjava index | Today | | Search | Google Search | Plain-Text | plain, newest first | summary

##friendlyjava on freenode