出于某种原因,我现在决定将我的 webapp 连接方法从简单的托管连接更改为池化数据源。一切正常,除了 mysqldump 在 BufferedReader 的迭代期间导致 OutOfMemoryError 之外。正如您在此处粘贴的代码中看到的那样,我尝试通过运行外部进程来进行转储......所以我无法弄清楚为什么会出现这个异常。
谁能帮我?
/**
* esegue il comando mysqldump e inserisce il risultato in un array di byte che poi verrà restituito sotto forma di stringa
* @return
* @throws Exception
*/
private String getData() throws Exception {
Process run = null;
InputStream inErr = null;
BufferedReader brErr = null;
StringBuffer tempErr = null;
InputStream in = null;
BufferedReader br = null;
StringBuffer temp = null;
try {
int count;
char[] cbuf = new char[BUFFER];
// esegue il backup con mysqldump
run = Runtime.getRuntime().exec("mysqldump --host=" + host + " --port=" + port + " --user=" + user + " --password=" + password + " " + db);
// prima gestisce un eventuale errore
inErr = run.getErrorStream();
brErr = new BufferedReader(new InputStreamReader(inErr));
tempErr = new StringBuffer();
if (inErr.available() != 0) {
while ((count = brErr.read(cbuf, 0, BUFFER)) != -1)
tempErr.append(cbuf, 0, count);
}
brErr.close();
inErr.close();
// scrive il testo dell'errore in un file
if (tempErr.toString().length() != 0) {
// scrive l'errore nel file di log
scriviErrInLog(tempErr.toString());
throw new Exception("Errore nel backup del database");
}
// ora gestisce un
in = run.getInputStream();
br = new BufferedReader(new InputStreamReader(in));
temp = new StringBuffer();
//System.out.println("creato input stream --- in.available() = " + in.available());
if ((count = br.read(cbuf, 0, BUFFER)) != -1) {
//System.out.println("sto per scrivere nel file");
temp.append(cbuf, 0, count);
br.mark(BUFFER);
br.reset();
while ((count = br.read(cbuf, 0, BUFFER)) != -1) {
temp.append(cbuf, 0, count);
}
//System.out.println("scritto");
br.close();
in.close();
run.destroy();
} else
throw new BackupException("Errore nel backup del database: backup vuoto");
} catch (Exception e) {
br.close();
in.close();
brErr.close();
inErr.close();
run.destroy();
throw e;
}
return temp.toString();
}
谢谢
ott 15, 2013 3:51:08 PM org.apache.tomcat.jdbc.pool.ConnectionPool abandon
警告:连接已被放弃 PooledConnection[com.mysql.jdbc.JDBC4Connection@1c3e12b]:java.lang.Exception at org.apache.tomcat.jdbc.pool.ConnectionPool.getThreadDump(ConnectionPool.java:976) at org.apache。 tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:730) 在 org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:586) 在 org.apache.tomcat.jdbc.pool.ConnectionPool。 getConnection(ConnectionPool.java:174) at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:124) at qbnuovo.dao.DBManager.openConnection(DBManager.java:174) at qbnuovo.dao.DBManager .exeQuery(DBManager.java:60) 在 qbnuovo.dao.TurnoDAO.selectPianoLavoro(TurnoDAO.java:2116) 在 qbnuovo.dao.TurnoDAO.selectPianoLavoro(TurnoDAO.java:2072) 在 qbnuovo.service.TurnoService。selectPianoLavoro(TurnoService.java:577) at qbnuovo.command.VisualizzaConsuntivoCommand.execute(VisualizzaConsuntivoCommand.java:294) at qbnuovo.web.RequestProcessor.perform(RequestProcessor.java:49) at qbnuovo.web.EventController.processRequest(EventController.java :144) 在 qbnuovo.web.EventController.doGet(EventController.java:184) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:第 722 章.invoke(StandardWrapperValve.java:224) 在 org.apache.catalina.core.StandardContextValve。在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) 的调用(StandardContextValve.java:169) .catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java :118) 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987) 在 org.apache.coyote.AbstractProtocol$ 的 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) AbstractConnectionHandler.process(AbstractProtocol.java:539) 在 org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298) 在 java.util。concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
MySqlBackup:线程“http-bio-8080-exec-1”java.lang.OutOfMemoryError 中的 prima di getData 异常:java.lang.AbstractStringBuilder.expandCapacity 的 java.util.Arrays.copyOf(未知来源)处的 Java 堆空间(未知源) 在 java.lang.AbstractStringBuilder.ensureCapacityInternal(Unknown Source) 在 java.lang.AbstractStringBuilder.append(Unknown Source) 在 java.lang.StringBuffer.append(Unknown Source) 在 qbnuovo.helper.MysqlBackup.getData(MysqlBackup.java :351) 在 qbnuovo.dao.DBManager.eseguiBackupDatabase(DBManager.java:461) 在 qbnuovo.dao.DBManager.eseguiBackupInterno(DBManager.java:710) 在 qbnuovo.helper.MysqlBackup.eseguiBackup(MysqlBackup.java:272) 在 qbnuovo .command.CambioDataCommand.execute(CambioDataCommand.java:124) 在 qbnuovo.web.RequestProcessor.perform(RequestProcessor.java:49) 在 qbnuovo.web.EventController.processRequest(EventController.java:144) 在 qbnuovo.web.EventController.doPost(EventController.java:193) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:641) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) at org.apache.catalina.authenticator .AuthenticatorBase.invoke(AuthenticatorBase.java:472) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) 在 org.org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928) 中的 apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987) at org.apache.coyote.AbstractProtocol $AbstractConnectionHandler.process(AbstractProtocol.java:539) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java .util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 在 org.apache.catalina.invoke(AccessLogValve.java:928) 调用(ErrorReportValve.java:98) .catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java :539) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker .run(Unknown Source) at java.lang.Thread.run(Unknown Source)在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 在 org.apache.catalina.invoke(AccessLogValve.java:928) 调用(ErrorReportValve.java:98) .catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java :539) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker .run(Unknown Source) at java.lang.Thread.run(Unknown Source)928) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 在 org.apache.coyote.http11.AbstractHttp11Processor 的 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) .process(AbstractHttp11Processor.java:987) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300 ) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 在 java.lang.Thread.run(Unknown Source) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)928) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 在 org.apache.coyote.http11.AbstractHttp11Processor 的 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) .process(AbstractHttp11Processor.java:987) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300 ) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 在 java.lang.Thread.run(Unknown Source) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539) 在 org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint. java:300) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539) 在 org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint. java:300) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)在 java.lang.Thread.run(Unknown Source) 处运行(Unknown Source)在 java.lang.Thread.run(Unknown Source) 处运行(Unknown Source)