public void destroy() {
   if (theServlet != null) {
     theServlet.destroy();
     InstanceManager instanceManager = InstanceManagerFactory.getInstanceManager(config);
     try {
       instanceManager.destroyInstance(theServlet);
     } catch (Exception e) {
       Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
       ExceptionUtils.handleThrowable(t);
       // Log any exception, since it can't be passed along
       log.error(Localizer.getMessage("jsp.error.file.not.found", e.getMessage()), t);
     }
   }
 }
  public Servlet getServlet() throws ServletException {
    // DCL on 'reload' requires that 'reload' be volatile
    // (this also forces a read memory barrier, ensuring the
    // new servlet object is read consistently)
    if (reload) {
      synchronized (this) {
        // Synchronizing on jsw enables simultaneous loading
        // of different pages, but not the same page.
        if (reload) {
          // This is to maintain the original protocol.
          destroy();

          final Servlet servlet;

          try {
            InstanceManager instanceManager = InstanceManagerFactory.getInstanceManager(config);
            servlet = (Servlet) instanceManager.newInstance(ctxt.getFQCN(), ctxt.getJspLoader());
          } catch (Exception e) {
            Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
            ExceptionUtils.handleThrowable(t);
            throw new JasperException(t);
          }

          servlet.init(config);

          if (!firstTime) {
            ctxt.getRuntimeContext().incrementJspReloadCount();
          }

          theServlet = servlet;
          reload = false;
          // Volatile 'reload' forces in order write of 'theServlet' and new
          // servlet object
        }
      }
    }
    return theServlet;
  }