Search code examples
javatomcatprintwriter

Exception in thread "ajp-bio-8009-exec-1"


I am facing strange error. My all java code runs without any problem on my laptop (windows 7) but when I upload it to our server (linux) then am seeing following in tomcat log:

Exception in thread "ajp-bio-8009-exec-1" java.lang.StackOverflowError
    at java.lang.System.checkKey(System.java:831)
    at java.lang.System.getProperty(System.java:705)
    at sun.security.action.GetPropertyAction.run(GetPropertyAction.java:84)
    at sun.security.action.GetPropertyAction.run(GetPropertyAction.java:49)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.io.PrintWriter.<init>(PrintWriter.java:116)
    at java.io.PrintWriter.<init>(PrintWriter.java:100)
    at mig.common.src.ErrorCheck.errorMsg(ErrorCheck.java:50)
    at mig.common.src.SendEmail.send(SendEmail.java:71)
    at mig.common.src.ErrorCheck.errorMsg(ErrorCheck.java:54)
    at mig.common.src.SendEmail.send(SendEmail.java:71)
    at mig.common.src.ErrorCheck.errorMsg(ErrorCheck.java:54)
    at mig.common.src.SendEmail.send(SendEmail.java:71)

Here is my ErrorCheck.errorMsg code:

public String errorMsg(String subject, Exception e){    
        String stackTrace = "";                 
        try{
            StringWriter sw = new StringWriter();  
                    PrintWriter pw = new PrintWriter(sw);  
                        e.printStackTrace(pw);
                            stackTrace = sw.toString();          
                        stackTrace = stackTrace.replaceAll("\n","<br>");                        SendEmail.send("[email protected]","[email protected]",subject,stackTrace);         
                pw.close();
                pw = null;      
            sw.close();
            sw = null;

            System.gc();

        }catch(Exception ex){
        ex.printStackTrace();
        }           
    return stackTrace;
    }

Please advise.

Thanks in anticipation


Solution

  • The actual problem was as following:

    I was writing in my code:

    ErrorCheck ec = new ErrorCheck();
    String error = ec.error();
    

    and then was calling in catch block

    ec.errorMsg(error+"SendEmail.send()", e);
    

    I removed from all classes error variable that was storing ec.error(); and corrected in my main class method errorMsg of ErrorCheck.java as following:

    String finalSubject = error()+subject;
            StringWriter sw = new StringWriter();  
                    PrintWriter pw = new PrintWriter(sw);  
                        e.printStackTrace(pw);
    

    Now its working fine