Vaadin ThreadLocal
I use the Vaadin Thread Local pattern in my Vaadin applications as a means to move the Application object around the various components and to implement a authentication process.
The structure of an application which uses this pattern is as follows:
| public class VaadinApplication extends Application implements HttpServletRequestListener { | 
private static ThreadLocal<VaadinApplication> instance = new ThreadLocal<VaadinApplication>()
| public VaadinApplication() { | 
| instance.set(this); | 
| } | 
| @Override | 
| public void onRequestStart(HttpServletRequest request, HttpServletResponse response) { | 
| instance.set(this); | 
| } | 
| @Override | 
| public void onRequestEnd(HttpServletRequest request, HttpServletResponse response) { | 
| instance.remove(); | 
| } | 
| public static VaadinApplication getInstance() { | 
| return instance.get(); | 
| } } | 
 
Comments
Post a Comment