开发者

How to prevent exception in parallel threads from killing the application?

I'm running a HtmlUnit web automation app. It usually works correctly, however, sometimes it goes overboard with StackOverflowError. That usually happens somew开发者_如何学Chere within its JS thread, and, hence, I can't catch it by surrounding the statement with try..catch.

As it stands, each time I get StackOverflow, the app crashes. I've tried to do this with

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.out.println("Uncaught exception in thread :"+t.getName());
            e.printStackTrace();    
            scr = new HtmlUnitWrapper();
        }
    });

but the app keeps crashing.

Is there anything else I can do to catch and process exceptions?


Stackoverflow is always going to be a fatal error in the JVM, it means the JVM stack is out of memory, there is nothing you can do to fix that.

It means that there is some method that is recursing and blowing out the stack.

Since you say, this is happening when there is Javascript on the page, I would assume that the Javascript is causing some kind of recursion, try changing the Javascript logic and see if that fixes the Stackoverflow problem, that is your root cause and the only way to "fix" this problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜