我从数据库中获取了大约17,500条记录,并在结果集执行步骤中完全降低了堆栈溢出错误。
Query query = dbConnect
.createQuery("select nitem from NItem nitem where nitem.id in ("+nitemIdStr+")");
nitemList = query.getResultList();
堆栈溢出错误
Root cause:
java.lang.StackOverflowError
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:98)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
at org.apache.openjpa.jdbc.kernel.exps.OrExpression.acceptVisit(OrExpression.java:99)
Complete stack:
org.apache.wicket.WicketRuntimeException: Method onRequest of interface org.apache.wicket.behavior.IBehaviorListener targeted at com.rambutan.test.ExportNew$3@17adeb on component [Form [Component id = ajaxexample]] threw an exception
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:268)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:247)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:226)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:854)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:254)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:211)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:282)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:247)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:226)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:854)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:254)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:211)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:282)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
我需要捕获此错误并在UI中显示一条消息,说明"文件导出超出堆栈限制,请使用过滤条件"而不是在浏览器中进入堆栈溢出错误。这有可能吗?
答案 0 :(得分:2)
以下示例在测试页面上为我工作:
getRequestCycleListeners().add(new AbstractRequestCycleListener() {
@Override
public IRequestHandler onException(RequestCycle cycle, Exception e) {
return new RenderPageRequestHandler(new PageProvider(SomePage.class));
}
});
在Application
中添加此内容,如果SomePage.class
发生异常,它会重定向您。
但是抓住堆栈溢出是不好的做法。有许多方法可以防止这种情况,例如限制查询,限制输入大小,跟踪已处理的记录或跟踪实际堆栈并自行完成。
所以我的建议是防止堆栈溢出而不是在wicket中捕获它。
答案 1 :(得分:1)
作为一般规则,捕捉错误是一个坏主意,因为它们通常意味着某些东西处于严重不一致的状态。
捕获国有企业尤其成问题,因为无法保证您能够对其采取行动。虽然在您的特定情况下,当您捕获它以允许进一步调用时,堆栈可能已经足够空,但是您可能会触发另一个SOE。
顺便说一下,你绝对不能这样做:
Query query = dbConnect
.createQuery("select nitem from NItem nitem where nitem.id in ("+nitemIdStr+")");
说真的,不要。