Java 7已经出现了一段时间了,但我找不到任何关于垃圾收集器配置的好资源,特别是新的G1收集器.
我的问题:
我如何正确地将字节压缩到a ByteArrayOutputStream然后使用ByteArrayInputStream?读取?我有以下方法:
private byte[] getZippedBytes(final String fileName, final byte[] input) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zipOut = new ZipOutputStream(bos);
ZipEntry entry = new ZipEntry(fileName);
entry.setSize(input.length);
zipOut.putNextEntry(entry);
zipOut.write(input, 0, input.length);
zipOut.closeEntry();
zipOut.close();
//Turn right around and unzip what we just zipped
ZipInputStream zipIn = new ZipInputStream(new ByteArrayInputStream(bos.toByteArray()));
while((entry = zipIn.getNextEntry()) != null) {
assert entry.getSize() >= 0;
}
return bos.toByteArray();
}
Run Code Online (Sandbox Code Playgroud)
当我执行此代码时,底部的断言失败,因为entry.size是-1.我不明白为什么提取的实体与压缩的实体不匹配.
java zip bytearrayoutputstream bytearrayinputstream zipoutputstream
我们在Solaris 10上运行了一个java进程,为大约200-300个并发用户提供服务.管理员报告说,进程使用的内存会随着时间的推移而显着增加.它在几天内达到2GB,并且永远不会停止增长.
我们已经倾倒堆和使用Eclipse内存分析器进行分析,但无法看到任何不寻常那里.堆大小非常小.
增加内存统计记录之后,我们的应用,我们发现通过"顶"工具,管理员使用,并通过MemoryMXBean和运行时库报道的使用报告的内存使用量之间的差异.
这是两者的输出.
Memory usage information
From the Runtime library
Free memory: 381MB
Allocated memory: 74MB
Max memory: 456MB
Total free memory: 381MB
From the MemoryMXBean library.
Heap Committed: 136MB
Heap Init: 64MB
Heap Used: 74MB
Heap Max: 456MB
Non Heap Committed: 73MB
Non Heap Init: 4MB
Non Heap Used: 72MB
Current idle threads: 4
Current total threads: 13
Current busy threads: 9
Current queue size: 0
Max threads: 200
Min threads: 8
Idle Timeout: 60000
PID USERNAME …Run Code Online (Sandbox Code Playgroud)