为什么我总是在JSP中遇到这个错误?
超过GC开销限制,有时堆大小
我正在使用Netbean IDE构建铁路票务网络应用程序。我被这个错误困住了。我尝试使用glassfishXX: MaxPermsize
和Xmx
的JVM设置来修复它。这个页面创建了很多对象,这个页面是为了生成一个随机的10位数机票号码并确认预订。
<table border="0" cellspacing="0" cellpadding="0" width="440">
<tr>
<td class="pageHeader"></td>
</tr>
<tr>
<td class="bodyText" style="font-size:10pt"><p> You have successfully booked your ticket !!
<%@ page language="java" import="java.sql.*, java.io.*, java.lang.*,java.util.*,java.math.*" %>
<%
String bookinfo = request.getParameter("info");
String args[] = bookinfo.split(",");
int Trainno = Integer.parseInt(args[0]);
String Trainname = args[1];
java.sql.Date Dat = java.sql.Date.valueOf(args[2]);
String tclass = args[3];
String From = args[4];
String To = args[5];
int Distance = Integer.parseInt(args[6]);
int Fare = Integer.parseInt(args[7]);
int seats = Integer.parseInt(args[8]);
String pname = request.getParameter("pname");
int age = Integer.parseInt(request.getParameter("age"));
String sex = request.getParameter("sex");
int coach = 0, seatno = 0;
String coachno = new String();
double range = 10000000000.0;
Random ran = new Random();
int PNRno = 0;
String PNR;
int flag = 0, flag2 = 0;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver"); // Oracle Driver
}
catch (java.lang.ClassNotFoundException e)
{
System.out.println("ClassNotFoundException: " + e.getMessage());
}
Connection con;
PreparedStatement ps;
PreparedStatement ps2;
ResultSet rs, rs2;
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/XE", "system", "hr");
String insertStmt2 = "SELECT PNRno,COACH,SEATNO FROM BOOKING WHERE STATUS = ? AND CLASS = ? AND COACH NOT LIKE ?";
ps2 = con.prepareStatement(insertStmt2);
ps2.setString(1, "CANCEL");
ps2.setString(2, tclass);
ps2.setString(3, "WL%");
rs2 = ps2.executeQuery();
if (rs2.next())
{
PNR = rs2.getString(1);
coachno = rs2.getString(2);
seatno = rs2.getInt(3);
insertStmt2 = "DELETE FROM BOOKING WHERE PNRno = ?";
ps2 = con.prepareStatement(insertStmt2);
ps2.setString(1, PNR);
rs2 = ps2.executeQuery();
if (rs2.next())
{
flag2 = 1;
}
}
String insertStmt = "INSERT INTO BOOKING VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
do
{
ps = con.prepareStatement(insertStmt);
PNRno = (int) ((ran.nextDouble()) * range);
ps.setString(1, String.valueOf(PNRno));
ps.setInt(2, Trainno);
ps.setString(3, Trainname);
ps.setDate(4, Dat);
ps.setString(5, tclass);
ps.setString(6, From);
ps.setString(7, To);
ps.setInt(8, Distance);
ps.setInt(9, Fare);
ps.setString(10, pname);
ps.setInt(11, age);
ps.setString(12, sex);
if (seats > 0 && flag2 == 0)
{
coach = (seats - 1) / 60 + 1;
seatno = ((seats - 1) % 60) + 1;
ps.setInt(16, 0);
if (tclass.equals("SL")) {
coachno = String.valueOf("S" + coach);
}
else if (tclass.equals("2A")) {
coachno = String.valueOf("A" + coach);
}
else if (tclass.equals("3A")) {
coachno = String.valueOf("B" + coach);
}
else {
coachno = String.valueOf("AC" + coach);
}
ps.setString(13, coachno);
ps.setInt(14, seatno);
ps.setString(15, "CONFIRM");
}
else if (flag2 == 0) {
ps.setInt(16, (Math.abs(seats) + 1));
ps.setString(13, "WL" + String.valueOf((Math.abs(seats) + 1)));
ps.setInt(14, 0);
ps.setString(15, "WAITING");
}
else {
ps.setString(13, coachno);
ps.setInt(14, seatno);
ps.setString(15, "CONFIRM");
ps.setInt(16, 0);
}
try {
flag = 0;
rs = ps.executeQuery();
}
catch (SQLException e) {
flag = 1;
}
}
while (flag == 1);
if (tclass.equals("SL")) {
insertStmt = "UPDATE SEATS SET \"SL\" = ? WHERE dat = ? AND trainno = ?";
} else if (tclass.equals("1A")) {
insertStmt = "UPDATE SEATS SET \"1A\" = ? WHERE dat = ? AND trainno = ?";
} else if (tclass.equals("2A")) {
insertStmt = "UPDATE SEATS SET \"2A\" = ? WHERE dat = ? AND trainno = ?";
} else if (tclass.equals("3A")) {
insertStmt = "UPDATE SEATS SET \"3A\" = ? WHERE dat = ? AND trainno = ?";
} else {
insertStmt = "UPDATE SEATS SET \"1C\" = ? WHERE dat = ? AND trainno = ?";
}
seats--;
ps = con.prepareStatement(insertStmt);
ps.setInt(1, seats);
ps.setDate(2, Dat);
ps.setInt(3, Trainno);
try
{
rs = ps.executeQuery();
rs.close();
}
catch (SQLException e)
{
}
finally
{
/*try
{
rs.close();
}
catch(SQLException e){}*/
try
{
ps.close();
}
catch(SQLException e){}
con.close();
}
%>
<form action="PNRHandler.jsp" method="get">
<input type="hidden" name="PNR" value="<%=PNRno%>" size="20" />
<br>
<input type="submit" name="Get Status" value="Get e-ticket">
</form>
</p>
<br /> </td>
<tr>
</table>
Severe: An exception or error occurred in the container during the request processing
java.lang.OutOfMemoryError: Java heap space
at java.util.LinkedList.listIterator(LinkedList.java:868)
at java.util.AbstractList.listIterator(AbstractList.java:299)
at java.util.AbstractSequentialList.iterator(AbstractSequentialList.java:239)
at org.apache.catalina.connector.CoyoteAdapter.enteringServletContainer(CoyoteAdapter.java:295)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:394)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
Severe: doSelect exception
java.lang.OutOfMemoryError: Java heap space
at java.util.ArrayList.iterator(ArrayList.java:834)
at sun.nio.ch.WindowsSelectorImpl.updateSelectedKeys(WindowsSelectorImpl.java:496)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:172)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at org.glassfish.grizzly.nio.DefaultSelectorHandler.select(DefaultSelectorHandler.java:113)
at org.glassfish.grizzly.nio.SelectorRunner.doSelect(SelectorRunner.java:339)
at org.glassfish.grizzly.nio.SelectorRunner.run(SelectorRunner.java:279)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
Warning: StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3332)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:137)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:121)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:421)
at java.lang.StringBuffer.append(StringBuffer.java:272)
at oracle.jdbc.driver.OracleSql.handleODBC(OracleSql.java:1249)
at oracle.jdbc.driver.OracleSql.parse(OracleSql.java:1192)
at oracle.jdbc.driver.OracleSql.getSql(OracleSql.java:326)
at oracle.jdbc.driver.OracleSql.getSqlBytes(OracleSql.java:661)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:215)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:58)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:943)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1075)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3820)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3867)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1502)
at org.apache.jsp.BookHandler2_jsp._jspService(BookHandler2_jsp.java:205)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
如果您的应用程序在GC上花费了太多的时间,超出GC开销限制的情况就会出现。
这个错误意味着GC试图释放内存,但几乎无法完成任何事情。默认情况下,当JVM花费超过98%的总时间在GC上,并且在GC之后恢复不到2%的堆时,就会发生这种情况。
您需要检查应用程序并关闭资源,以便GC可以释放它们
当我执行我的测试时,我得到了这个错误消息: 我知道什么是,但GC开销限制意味着什么?我怎样才能解决这个问题?
我正在IntelliJ Idea Ultimate Edition 2020.2.2上运行Grails 2.5.0。它可以很好地编译和构建代码,但它会不断抛出“java.lang.OutOfMemoryError:超出GC开销限制”错误(整个错误都是复制并粘贴在最后)。以下是我在研究这个错误的基础上尝试的东西: 1)增加构建进程堆大小(在2G、4G和6G下尝试)https://intellij-s
使用当我尝试构建我的项目时,这种错误越来越多: 错误:任务“:app:CompiledEbugJavaWithJavac”执行失败。OutofMemoryError:超出GC开销限制 有什么办法解决这个问题吗?
我正在尝试预处理一个大的txt文件(10G),并将其存储在二进制文件中以备将来使用。当代码运行时,速度会减慢,并以 异常线程"main"java.lang.OutOfMemoryError: GC开销限制超过 输入文件具有以下结构 这是我正在使用的代码: 基本上,它通过in文件并将数据存储到对象HMbicnt(这是一个哈希映射)。一旦在第二列中遇到新值,它应该将对象写入输出文件,释放内存并继续。
我正在开发一个Java程序,该程序将从Sybase数据库获取数据,并使用UCanAccess将其导入Microsoft Access数据库。但是,我目前遇到了一个问题,收到了错误“java.lang.OutOfMemoryError:超出了GC开销限制”。 为了将这种情况放到上下文中,我正在尝试将大约130万条记录导入Access数据库。在导入了大约800000条记录之后,在运行时大约十分钟,以及
问题内容: 我执行JUnit测试时收到以下错误消息: 我知道是什么OutOfMemoryError,但是GC开销限制是什么意思?我该如何解决? 问题答案: 该消息表示由于某种原因,垃圾收集器占用了过多的时间(默认情况下为该进程所有CPU时间的98%),并且每次运行时恢复的内存很少(默认为堆的2%)。 这实际上意味着你的程序停止任何进展,并且一直在忙于仅运行垃圾回收。 为了防止你的应用程序浪费CPU