|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.io.ObjectOutputStreamReset
public class ObjectOutputStreamReset
Enable a ObjectOutputStream for writing a lot of data.
The current design of the ObjectOutputStream
does not make it very usable when one needs to write out a large
number of different objects. The problem is that ObjectOutputStream maintains a reference to each object it
writes. This results in a huge "reference leak" affect (consumes a
lot of memory). This affect was discovered when implementing a
lightning data server - the server kept running out of memory
because references to each lightning event were being contained
(the server was unknowning keeping a copy of every lightning event
it sent to a client).
To avoid this, this class makes use of the reset method to periodically
clear the internal reference table maintained by the ObjectOutputStream to prevent massive consumption of
memory.
This class is basically a convience wrapper around the ObjectOutputStream class. To read data back, you can use
the standard ObjectInputStream class.
writeObject(java.lang.Object)| Constructor Summary | |
|---|---|
ObjectOutputStreamReset(OutputStream os,
int resetCnt)
Create a object with a specific "reset" count. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the stream. |
void |
flush()
Flush the stream. |
void |
writeObject(Object o)
Write a Serializable object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ObjectOutputStreamReset(OutputStream os,
int resetCnt)
throws IOException
constructor for the ObjectOutputStream
class. It does the following:
os - A OutputStream to write objects to.cnt - A "reset" count. This count indiciates how often the
underlying ObjectOutputStream should be reset as objects are
written. If you plan on writing large objects, this number
should be relatively low, if you plan on writing small
objects, set this number higher. As a general rule of thumb, I
like to set this number such that the object will be "reset"
after 100K of data has been written which is calculated as
(100K / "estimated size of average object"). Note, if you set
this value to a value less than or equal to 0, you will
disable the automatic "reset" capability of this class.
{@link - java.io.IOException}
If there is a problem constructing the underlying ObjectOutputStream object used by this class.
IOExceptionObjectOutputStreamReset(java.io.OutputStream, int)| Method Detail |
|---|
public void writeObject(Object o)
throws IOException
Serializable object.
This method first determines if its time to reset the underlying reference
table. If so, this table will be cleared (which reduces the
efficiency of the ObjectOutputStream class, but
prevents it from consuming vast amounts of memory). After making
the "reset" check, the object is then written to the underlying
ObjectOutputStream object.
o - A Serializable object to write out.
{@link - java.io.IOException}
If there is a problem writing the object to
the underlying stream.
IOException
public void flush()
throws IOException
write additional objects after invoking this method.
{@link - java.io.IOException}
If an I/O error has occurred.
IOExceptionwriteObject(java.lang.Object),
close()
public void close()
throws IOException
write more objects after invoking this
method.
{@link - java.io.IOException}
If an I/O error has occurred.
IOExceptionwriteObject(java.lang.Object),
flush()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||