Reputation: 3890
I have a few objects I am instantiating in and then using in JSPs. I've created these objects to lazy-load (rather than initialize in the cstor) on a number of getters as these operations are slow-ish, and not all are always used.
I know simple lazy loading can cause Thread-safety issues:
if(this.var == null) {
this.var = service.call();
}
return this.var;
However since these classes are ONLY ever called from JSPs (and CAN only be called due to the cstor's params which are exposed via the container only to JSPs), am I ok? Since its part of JSP execution, i wouldnt imagine that I have to worry about multiple threads, but wanted to get everyone's thoughts.
The app server this is running under is Jetty-based.
Upvotes: 0
Views: 70
Reputation: 31280
If you are not sharing objects between threads (or requests for a web application), you don't have to worry about thread safety issues.
If you are constructing the objects in the JSP, and then using them there, and the objects don't do any funny stuff behind the scenes that would cause issues, you should be fine.
Upvotes: 2