开发者

Is Blackberry's SimpleDateFormat thread safe?

开发者 https://www.devze.com 2023-01-09 18:54 出处:网络
Is the BlackBerry version of SimpleDateFormat, net.rim.dev开发者_如何学Pythonice.api.i18n.SimpleDateFormat thread safe? I know that java.text.SimpleDateFormat is not but there is no mention if net.rim

Is the BlackBerry version of SimpleDateFormat, net.rim.dev开发者_如何学Pythonice.api.i18n.SimpleDateFormat thread safe? I know that java.text.SimpleDateFormat is not but there is no mention if net.rim.device.api.i18n.SimpleDateFormat is thread safe or not. Should we assume if it is not stated then it is not thread safe?


Unless the javadoc for a class explicitly states that it is threadsafe, you should assume that it is not. Even if you can look at the source code and the class appears to be threadsafe, it may be non-threadsafe in the next release ...

The javadoc for DateFormat.getInstance(int) says:

Returns: New SimpleDateFormat instance with the provided style.

So, if you use this method you are guaranteed to get a new instance of the class. Provided that you don't share it between threads, thread safety should not be a concern.


The API doesn't mention.

It suggests using DateFormat.html#getInstance(int) which is some sort of factory method.

So what you can do is to call this method many times from different threads with the same parameter and see if it always returns the same object (compare with ==). If it is, then DateFormat probably caches the returned SimpleDateFormat instances. So since their API allows reuse you may assume that it is thread safe.

0

精彩评论

暂无评论...
验证码 换一张
取 消