运行我的应用程序时,经过 40000 个事务后,在 java.util.Properties.getProperty 处出现堆栈溢出异常。
请在下面找到堆栈错误..
java.lang.StackOverflowError
at java.util.Hashtable.get(Hashtable.java:334)
at java.util.Properties.getProperty(Properties.java:932)
at java.util.Properties.getProperty(Properties.java:934)
... 80,0000 times
at java.util.Properties.getProperty(Properties.java:934)
at java.lang.System.getProperty(System.java:653)
at sun.security.action.GetPropertyAction.run(GetPropertyAction.java:67)
at sun.security.action.GetPropertyAction.run(GetPropertyAction.java:32)
at java.security.AccessController.doPrivileged(Native Method)
at java.io.PrintWriter.<init>(PrintWriter.java:78)
at java.io.PrintWriter.<init>(PrintWriter.java:62)
at java.util.logging.SimpleFormatter.format(SimpleFormatter.java:71)
at org.apache.juli.FileHandler.publish(FileHandler.java:133)
at java.util.logging.Logger.log(Logger.java:481)
at java.util.logging.Logger.doLog(Logger.java:503)
at java.util.logging.Logger.logp(Logger.java:703)
at org.apache.commons.logging.impl.Jdk14Logger.log(Jdk14Logger.java:101)
at org.apache.commons.logging.impl.Jdk14Logger.error(Jdk14Logger.java:149)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:253)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:662)
我无法追踪抛出堆栈错误的位置。
最佳答案
无意陈述显而易见的事实,但也许您应该检查是否在执行这些事务的循环内创建变量(40.000 次重复:-)),而不是重用相同的变量。此外,检查循环内的约束可能会产生不必要的负载。 字符串连接也会产生大量负载。所以,如果你有这样的事情:
for (i=0; i < getNumberOfTransactions(); i++){ // constraint checking inside the loop
int currentValue = myTransaction.getSomeData(); // creating new variable in every
}
你应该这样写:
int numberOfTransactions = getNumberOfTransactions();
int currentValue = 0;
for(i=0; i < numberOfTransactions; i++){
currentValue = myTransaction.getSomeData();
}
尽管此示例仅使用 2 个整型变量,但当在循环内创建多个变量(尤其是字符串连接)时,这可能会消耗大量内存。如果您有一些字符串连接,请使用 StringBuilder 类。
关于java - java.util.Properties.getProperty 处的堆栈溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13601851/