我有一個非常大的對象,我想序列化。在序列化過程中,它佔用大約130MB的堆作爲weblogic.utils.io.UnsyncByteArrayOutputStream。我正在使用BufferedOutputStream來加速將數據寫入磁盤,這可以減少此對象在內存中的存儲時間。在java序列化過程中可以緩存對象嗎?
雖然可以使用緩衝區來減少內存中對象的大小嗎?如果有一種方法一次將其序列化爲x個字節並將這些字節寫入磁盤將會很好。
如果有任何用途,請遵循示例代碼。儘管我不這麼認爲,但還沒有太多的事情要做。如果這種情況需要一個完整的內存中要被序列化的對象的副本(因此沒有序列化緩衝區的概念),那麼我認爲我被卡住了。
ObjectOutputStream tmpSerFileObjectStream = null;
OutputStream tmpSerFileStream = null;
BufferedOutputStream bufferedStream = null;
try {
tmpSerFileStream = new FileOutputStream(tmpSerFile);
bufferedStream = new BufferedOutputStream(tmpSerFileStream);
tmpSerFileObjectStream = new ObjectOutputStream(bufferedStream);
tmpSerFileObjectStream.writeObject(siteGroup);
tmpSerFileObjectStream.flush();
} catch (InvalidClassException invalidClassEx) {
throw new SiteGroupRepositoryException(
"Problem encountered with class being serialised", invalidClassEx);
} catch (NotSerializableException notSerializableEx) {
throw new SiteGroupRepositoryException(
"Object to be serialized does not implement " + Serializable.class,
notSerializableEx);
} catch (IOException ioEx) {
throw new SiteGroupRepositoryException(
"Problem encountered while writing ser file", ioEx);
} catch (Exception ex) {
throw new SiteGroupRepositoryException(
"Unexpected exception encountered while writing ser file", ex);
} finally {
if (tmpSerFileObjectStream != null) {
try {
tmpSerFileObjectStream.close();
if(null!=tmpSerFileStream)tmpSerFileStream.close();
if(null!=bufferedStream)bufferedStream.close();
} catch (IOException ioEx) {
logger.warn("Exception caught on trying to close ser file stream", ioEx);
}
}
}
你可以發佈你的序列化邏輯的一些示例代碼?這裏沒有東西加在一起 - 這個weblogic類從哪裏來? – 2010-07-01 12:00:07