我正在使用TrueZip
進行壓縮。這裏是我的代碼是什麼樣子TrueZip壓縮佔用太多時間
public String compress() throws IOException {
if (logLocations.isEmpty()) {
throw new IllegalStateException("no logs provided to compress");
}
removeDestinationIfExists(desiredArchive);
final TFile destinationArchive = new TFile(desiredArchive + "/diagnostics");
for (final String logLocation : logLocations) {
final TFile log = new TFile(logLocation);
if (!log.exists()) {
LOGGER.debug("{} does not exist, ignoring.");
continue;
}
if (log.isDirectory()) {
log.cp_r(destinationArchive);
} else {
final String newLogLocation =
new TFile(destinationArchive.getAbsolutePath()) + SLASH +
getLogNameFromPath(logLocation);
log.cp(new TFile(newLogLocation));
}
}
return destinationArchive.getEnclArchive().getAbsolutePath();
}
和我的測試
@Test
public void testBenchMarkWithHprof() throws IOException {
final FileWriter logLocations;
String logLocationPath = "/Users/harit/Downloads/tmp/logLocations.txt";
{
logLocations = new FileWriter(logLocationPath);
logLocations.write("Test3");
logLocations.write("\n");
logLocations.close();
}
final LPLogCompressor compressor = new LPLogCompressor("/Users/harit/Downloads/tmp",
new File(logLocationPath),
"/Users/harit/Downloads/tmp/TestOut");
final long startTime = System.currentTimeMillis();
compressor.compress();
System.out.println("Time taken (msec): " + (System.currentTimeMillis() - startTime));
}
和我的數據目錄Test3
看起來像
Test3/
java_pid1748.hprof
的文件大小爲2.83GB
當我運行測試,它接管了22分鐘。
然而,當我使用壓縮的Native OSX compress (right click -> compress)
相同的文件,只需要2分鐘
爲什麼有這麼大的區別呢?
感謝
UPDATE
基於@Satnam的建議,我連着一個調試器,看看怎麼回事,這是我找到
無的TrueZip線程正在運行?真?道歉我第一次使用探查器
爲什麼不使用探查? – satnam
是否存在差異 - 文件屬性,如所有者和只讀存儲? (可在小目錄上測試)。使用標準的java意味着可以創建一個zip文件系統,只需使用'Files.copy'複製一個操作即可將磁盤中的目錄複製到zip中。 –
@satnam,我更新了快照,你看到差異了嗎? – daydreamer