【发布时间】:2011-06-24 03:04:48
【问题描述】:
我有一个在 xml 中定义了初始化方法的类
<bean id="appStarter" class="com.myapp.myClass" init-method="init" destroy-method="destroy"/>
我的班级:
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();
}
}
应用启动时,这些线程运行良好,一切正常 一段时间后我得到以下异常。
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.java:510)
在doStuff方法中:
public void doStuff(){
Session sessioned = Session.getDefaultInstance(System.getProperties(),
null);
Store store = sessioned.getStore("imap");
store.connect(hostName, userName, password);
.
.
.
}
我不知道为什么,有什么想法吗?
【问题讨论】:
-
也许你可以尝试在你的destory事件中添加一些释放函数调用(只是链接Singleton,连接池)。
标签: java multithreading tomcat jakarta-ee jakarta-mail