I've seen the builder pattern recommended in a variety of places, but wasn't sure on thread safety within a Web application using Struts.
I am unclear as to whether the variables of the build
static method are shared by, or internal to each thread that invokes the builder code. I have a hunch it's okay, but want to be sure given that the builder code lives inside a Web application and could be invoked by 10s of threads at once.
public static class ExampleBuilder {
public static Thing build(ActionForm form) {
String property1 = form.property1;
String property2 = form.property2;
String propertyX = form.propertyX;
...
return new Thing(property1, ...);
}
}
public class ExampleStrutsAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
Thing example = ExampleBuilder.build(form)
return mapping.findForward("success");
}
}