()
| 910 | |
| 911 | |
| 912 | @Override |
| 913 | public synchronized void unload() throws ServletException { |
| 914 | |
| 915 | // Nothing to do if we have never loaded the instance |
| 916 | if (instance == null) { |
| 917 | return; |
| 918 | } |
| 919 | unloading = true; |
| 920 | |
| 921 | // Loaf a while if the current instance is allocated. Use wait() to |
| 922 | // release the lock while waiting to avoid blocking other threads. |
| 923 | if (countAllocated.get() > 0) { |
| 924 | int nRetries = 0; |
| 925 | long delay = unloadDelay / 20; |
| 926 | while ((nRetries < 21) && (countAllocated.get() > 0)) { |
| 927 | if ((nRetries % 10) == 0) { |
| 928 | log.info(sm.getString("standardWrapper.waiting", countAllocated.toString(), getName())); |
| 929 | } |
| 930 | try { |
| 931 | wait(delay); |
| 932 | } catch (InterruptedException e) { |
| 933 | // Ignore |
| 934 | } |
| 935 | nRetries++; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | ServletException servletException = null; |
| 940 | |
| 941 | if (instanceInitialized) { |
| 942 | PrintStream out = System.out; |
| 943 | if (swallowOutput) { |
| 944 | SystemLogHandler.startCapture(); |
| 945 | } |
| 946 | |
| 947 | // Call the servlet destroy() method |
| 948 | try { |
| 949 | instance.destroy(); |
| 950 | } catch (Throwable t) { |
| 951 | Throwable throwable = ExceptionUtils.unwrapInvocationTargetException(t); |
| 952 | ExceptionUtils.handleThrowable(throwable); |
| 953 | servletException = new ServletException(sm.getString("standardWrapper.destroyException", getName()), throwable); |
| 954 | } finally { |
| 955 | // Annotation processing |
| 956 | if (!((Context) getParent()).getIgnoreAnnotations()) { |
| 957 | try { |
| 958 | ((Context) getParent()).getInstanceManager().destroyInstance(instance); |
| 959 | } catch (Throwable t) { |
| 960 | ExceptionUtils.handleThrowable(t); |
| 961 | log.error(sm.getString("standardWrapper.destroyInstance", getName()), t); |
| 962 | } |
| 963 | } |
| 964 | // Write captured output |
| 965 | if (swallowOutput) { |
| 966 | String log = SystemLogHandler.stopCapture(); |
| 967 | if (log != null && !log.isEmpty()) { |
| 968 | if (getServletContext() != null) { |
| 969 | getServletContext().log(log); |
no test coverage detected