typhoid / google-gson

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

Document that Gson instances are thread safe #613

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Issue #63 [1] and the gson mailing list [2] indicate that Gson instances are 
thread safe. It would be good to document that in the Gson class, either in the 
Javadoc or with a JSR-305 @ThreadSafe annotation.

Background for this request is that I recently found quite a few places in 
multi-threaded code where Gson instances were unnecessarily created because the 
developers didn't know that these instances are thread safe.

[1] http://code.google.com/p/google-gson/issues/detail?id=63
[2] https://groups.google.com/forum/#!topic/google-gson/Vju1HuJJUIE

Original issue reported on code.google.com by st.fer...@gmail.com on 28 Nov 2014 at 1:42

GoogleCodeExporter commented 9 years ago
I created a patch that adds a JSR-305 @ThreadSafe annotation to the Gson class.

I declared the dependency to the JSR-305 library as optional so that it doesn't 
get downloaded transitively when using google-gson. This is fine because the 
@ThreadSafe annotation has only a documentary purpose and it is not retained at 
runtime.

Original comment by st.fer...@gmail.com on 29 Nov 2014 at 11:16

Attachments: