나는 직렬화하고자하는 매우 큰 객체를 가지고있다. 직렬화 과정에서 130MB의 힙을 weblogic.utils.io.UnsyncByteArrayOutputStream으로 사용하게됩니다. BufferedOutputStream을 사용하여 디스크에 데이터를 쓰는 속도를 높이고이 개체가 메모리에 보관되는 시간을 줄입니다.자바 직렬화 중에 객체를 버퍼링 할 수 있습니까?
버퍼를 사용하여 메모리에있는 개체의 크기를 줄일 수 있습니까? 한 번에 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 클래스는 어디서 왔습니까? –