AnsweredAssumed Answered

A.E: race conditions because no synchronization possible?

Question asked by udoderk on Feb 17, 2013
Latest reply on Feb 18, 2013 by frederikheremans1
Hi everybody,
i look at org.activiti.explorer.ExplorerApp class

public class ExplorerApp extends Application implements HttpServletRequestListener {
 
  private static final long serialVersionUID = -1L;

  // Thread local storage of instance for each user
  protected static ThreadLocal<ExplorerApp> current = new ThreadLocal<ExplorerApp>();
 
  protected String environment;
  protected UserCache userCache;
  protected MainWindow mainWindow;
  protected ViewManager viewManager;
  protected NotificationManager notificationManager;
  protected I18nManager i18nManager;
  protected AttachmentRendererManager attachmentRendererManager;
  protected FormPropertyRendererManager formPropertyRendererManager;
  protected VariableRendererManager variableRendererManager;
  protected LoginHandler loginHandler;
  protected WorkflowDefinitionConversionFactory workflowDefinitionConversionFactory;
  protected ComponentFactories componentFactories;

and think about whether race conditions  (RCs) are possible, beacause no synchronization for protected varibales exist. Only ThreadLocal is used to get a access (for each registered thread) on components of ExplorerApp.

Theoretically RCs should not exist after call of the "activiti-explorer" uri in browser, beacuse:
At first time the org.activiti.explorer.servlet.ExplorerApplicationServlet will be created.
That Servlet will be injected into first thread, that process the servlet.
The method "service() will be called. Within of that method the application will be created using spring's WebApplicationContextUtils


  @Override
  public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletConfig.getServletContext());
  }

  @Override
  protected Class< ? extends Application> getApplicationClass() throws ClassNotFoundException {
    return ExplorerApp.class;
  }

  @Override
  protected Application getNewApplication(HttpServletRequest request) {
    return (Application) applicationContext.getBean(ExplorerApp.class);
  }

The WebApplicationContextUtils should be used same thread context, that was created during GET-Request.
If the second GET-Request occurs, so the thread from thread poll will be used. (That may be new thread).
Thus, the application will be loaded in another thread context.

So quasi single thread model for each user exists…

But this is only theory…

Thanks for your replays!

Outcomes