Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I want to create a static variable that I can initialize once and then re-use. There are a few places I want to do this - a compiled regular expression, a SimpleDateFormat, there are a number of objects in Java that are useful to create once and re-use.
At the moment I am creating the objects in a tJava component and pushing them into the globalMap or a sharedMap object. That means that every time I access one of them, I have to pull it out of the map and cast it to the right class.
Is there a better way of doing this?
I solved my problem by creating a code entry like this:
public class statics_for_phil {
public static java.text.SimpleDateFormat format_YYYYMMDD;
public static java.util.regex.Pattern file_name_split;
static {
format_YYYYMMDD = new java.text.SimpleDateFormat("yyyyMMdd");
file_name_split = java.util.regex.Pattern.compile("^S3_(\\d+)_([a-z]+)_(\\d+)");
}
}
I solved my problem by creating a code entry like this:
public class statics_for_phil {
public static java.text.SimpleDateFormat format_YYYYMMDD;
public static java.util.regex.Pattern file_name_split;
static {
format_YYYYMMDD = new java.text.SimpleDateFormat("yyyyMMdd");
file_name_split = java.util.regex.Pattern.compile("^S3_(\\d+)_([a-z]+)_(\\d+)");
}
}