Exception in thread "main":java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler

最近部署一个maven项目,tomcat启动快要完成的时候,突然停住,然后爆出红色字体提示: Exception in Thread "main"; 我以为接下来会有大量的bug信息出现,然后左等右等,没了!没有任何提示,真不知该如何下手。最后我抛开eclipse,直接启动了tomcat,总算出来了bug信息:

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "http-bio-80-exec-31“,这也算,通过网查,找到如下解决方案:

在tomcat_home/bin目录下找到catalina.bat,用文本编辑器打开,加上下面一行:
set JAVA_OPTS= -Xms1024M -Xmx1024M -XX:PermSize=256M -XX:MaxNewSize=256M -XX:MaxPermSize=256M
解释一下各个参数:
-Xms1024M:初始化堆内存大小(注意,不加M的话单位是KB)
-Xmx1029M:最大堆内存大小

-XX:PermSize=256M:初始化类加载内存池大小

-XX:MaxPermSize=256M:最大类加载内存池大小

加载完成,启动tomcat,OK,问题解决。

但是,在eclipse中启动tomcat,如果问题依然没有解决。

直接双击tomcat服务器,然后进入tomcat配置,选择Open launcher configuration,进入配置页面,如图:



在Argument中末尾添加参数中的VM arguments中追加:

-Xms256M -Xmx512M -XX:PermSize=256m -XX:MaxPermSize=512m