我的应用程序当前正在使用 CSV 解析器来解析 csv 文件并保存到数据库。它将整个 csv 加载到内存中并花费大量时间来保存,有时甚至超时。我在网站上看到了
使用 Univocity 解析器的混合建议。请建议处理大量数据且花费更少时间的最佳方法。
谢谢。
代码:
int numRecords = csvParser.parse( fileBytes );
public int parse(InputStream ins) throws ParserException {
long parseTime= System.currentTimeMillis();
fireParsingBegin();
ParserEngine engine = null;
try {
engine = (ParserEngine) getEngineClass().newInstance();
} catch (Exception e) {
throw new ParserException(e.getMessage());
}
engine.setInputStream(ins);
engine.start();
int count = parse(engine);
fireParsingDone();
long seconds = (System.currentTimeMillis() - parseTime) / 1000;
System.out.println("Time taken is "+seconds);
return count;
}
protected int parse(ParserEngine engine) throws ParserException {
int count = …Run Code Online (Sandbox Code Playgroud)