Is there any reason why a variable can't be created in a Java ServletContextListener and it's value set and get like any other. What I have is an ArrayList in an SCL and a method in another class updates the ArrayList every so often using static get and set methods in the SCL itself. My preference here is not to use ServletContext to store the ArrayList.
No new instance of the listener is ever created at all.
Code in the SCL is similar to below:
private static ArrayList<String> strList;
@Override
public void contextInitialized(ServletContextEvent contextEvent) {
ArrayList<String> temp = someOtherMethod();
setStrList(temp);
}
@Override
public void contextDestroyed(ServletContextEvent contextEvent) {
}
public static ArrayList<String> getStrList() {
// ...
return strList;
}
public static void setStrList(ArrayList<String> temp) {
this.strList = temp;
// ...
}