Is there any general way or rule existing by which we can ensure the thread safety of static methods specifically used in various Utility classes of any applications? Here I want to specifically point out the thread safety of Web Applications.
It is well known that static methods with Immutable Objects as parameters are thread safe and Mutable Objects are not.
If I have a utility method for some manipulation with java.util.Date and that method accepts an instance of java.util.Date, then this method is not thread safe. Then how to make it thread safe without changing the way of parameter passing?
public class DateUtils {
public static Date getNormalizeDate(Date date) {
// some operations
}
}
Also is the class javax.faces.context.FacesContext mutable? Is it thread safe to pass an instance of this class to such static utility method?
This list of classes, instances of which can be or cannot be passed as parameters, could be long; so what points should we keep in mind while writing codes of such utility classes?