开发者

Illegal access: this web application instance has been stopped already

开发者 https://www.devze.com 2023-02-09 05:49 出处:网络
I have a class which has an init-method defined in xml <bean id=\"appStarter\" class=\"com.myapp.myClass\" init-method=\"init\" destroy-method=\"destroy\"/>

I have a class which has an init-method defined in xml

<bean id="appStarter" class="com.myapp.myClass" init-method="init" destroy-method="destroy"/>

myClass:

public class myClass{

    private Thread t;

    public void init() {

             t = new Thread() {

                @Override
                public void run() {
                    while (true)
                        try {
                            doStuff();
                            Thread.sleep(1000);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                }

            };
            t.start();
        }

public void destroy() {
        t.interrupt();
    }

}

When the app starts, these threads run fine, and everything works just fine and after sometime i get the following exception.

INFO: Illegal access: this web application instance has been stopped already.  Could not load com.sun.mail.imap.IMAPStore.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1273)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    at javax.mail.Session.getService(Session.java:755)
    at javax.mail.Session.getStore(Session.java:569)
    at javax.mail.Session.getStore(Session.java:531)
    at javax.mail.Session.getStore(Session.j开发者_开发知识库ava:510)

in the doStuff method:

public void doStuff(){

Session sessioned = Session.getDefaultInstance(System.getProperties(),
                null);
        Store store = sessioned.getStore("imap");
        store.connect(hostName, userName, password);
.
.
.

}

I don't know why, any ideas ?


Problem solved after restarting the tomcat and apache, the tomcat was caching older version of the app.


In short: this happens likely when you are hot-deploying webapps. For instance, your ide+development server hot-deploys a war again. Threads, that have been created previously are still running. But meanwhile their classloader/context is invalid and faces the IllegalAccessException / IllegalStateException becouse its orgininating webapp (the former runtime-environment) has been redeployed.

So, as states here, a restart does not permanently resolve this issue. Instead, it is better to find/implement a managed Thread Pool, s.th. like this to handle the termination of threads appropriately. In JavaEE you will use these ManagedThreadExeuctorServices. A similar opinion and reference here.

Examples for this are the EvictorThread of Apache Commons Pool, that "cleans" pooled instances according to the pool's configuration (max idle etc.).


I suspect that this occurs after an attempt to undeploy your app. Do you ever kill off that thread that you've initialised during the init() process ? I would do this in the corresponding destroy() method.


Restarting Your Server Can Resolve this problem.

I was getting the same error while Using Dynamic Jasper Reporting , When i deploy my Application for first use to Create Reports, the Report creation works fine, But Once I Do Hot Deployment of some code changes To the Server, I was getting This Error.


If it's a local development tomcat launched from IDE, then restarting this IDE and rebuild project also helps.

Update:

You could also try to find if there is any running tomcat process in the background and kill it.


I had this exact error. My app ran fine inside of the eclipse development environment but when deployed to the production Tomcat server, the app would load fine, then when an endpoint was called, it generated the error:

[Abandoned connection cleanup thread] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load []

The error was caused because there were two different java versions. My development environment in eclipse was set to jdk-15 and the production server was running version 11.

To fix the issue, in eclipse, even when using jdk-15, I emulated java-11:

Illegal access: this web application instance has been stopped already

Illegal access: this web application instance has been stopped already

Illegal access: this web application instance has been stopped already

0

精彩评论

暂无评论...
验证码 换一张
取 消