gpt4 book ai didi

java - 如果tomcat使用数据源,由tomcat启动的mysqldump导致OutOfMemoryError

转载 作者:行者123 更新时间:2023-11-28 23:41:15 25 4
gpt4 key购买 nike

由于某种原因,我现在决定将我的webapp连接方法从简单的托管连接更改为池化DataSource。除了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
    在org.apache.tomcat.jdbc.pool.ConnectionPool.getThreadDump(ConnectionPool.java:976)
    在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)
    在org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:124)
    在qbnuovo.dao.DBManager.openConnection(DBManager.java:174)
    在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)
    在qbnuovo.command.VisualizzaConsuntivoCommand.execute(VisualizzaConsuntivoCommand.java:294)
    在qbnuovo.web.RequestProcessor.perform(RequestProcessor.java:49)
    在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)
    在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
    在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    在org.apache.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)
    在org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:298)
    在java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)
    在java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)
    在java.lang.Thread.run(未知来源)

MySqlBackup:基本的getData
线程“ http-bio-8080-exec-1”中的异常java.lang.OutOfMemoryError:Java堆空间
    在java.util.Arrays.copyOf(未知来源)
    在java.lang.AbstractStringBuilder.expandCapacity(来源不明)
    在java.lang.AbstractStringBuilder.ensureCapacityInternal(未知来源)
    在java.lang.AbstractStringBuilder.append(未知来源)
    在java.lang.StringBuffer.append(未知来源)
    在qbnuovo.helper.MysqlBackup.getData(MysqlBackup.java:351)
    在qbnuovo.helper.MysqlBackup.eseguiBackup(MysqlBackup.java:272)
    在qbnuovo.dao.DBManager.eseguiBackupInterno(DBManager.java:710)
    位于qbnuovo.dao.DBManager.eseguiBackupDatabase(DBManager.java:461)
    在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)
    在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
    在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    在org.apache.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)
    在org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:300)
    在java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)
    在java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)
    在java.lang.Thread.run(未知来源)

最佳答案

问题是,您试图将整个mysql转储保留在内存中,这必然会以这种错误结束。它与池化的DataSource没有任何关系。
从输入流中读取时,尝试逐行处理转储。

关于java - 如果tomcat使用数据源,由tomcat启动的mysqldump导致OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19382460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com