public void undeploy(BeanContext beanContext) {

    EjbTimerService timerService = beanContext.getEjbTimerService();
    if (timerService != null) {
      timerService.stop();
    }

    instanceManager.undeploy(beanContext);

    synchronized (this) {
      String id = (String) beanContext.getDeploymentID();
      beanContext.setContainer(null);
      beanContext.setContainerData(null);
      deploymentRegistry.remove(id);
    }
  }
  public void undeploy(BeanContext beanContext) {
    ThreadContext threadContext = new ThreadContext(beanContext, null);
    ThreadContext old = ThreadContext.enter(threadContext);
    try {
      instanceManager.freeInstance(threadContext);
    } finally {
      ThreadContext.exit(old);
    }

    EjbTimerService timerService = beanContext.getEjbTimerService();
    if (timerService != null) {
      timerService.stop();
    }

    instanceManager.undeploy(beanContext);

    synchronized (this) {
      String id = (String) beanContext.getDeploymentID();
      beanContext.setContainer(null);
      beanContext.setContainerData(null);
      deploymentRegistry.remove(id);
    }
  }