I want to convert my pojo objects into byte arrays. All of my objects are serializable. I use
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream o = new ObjectOutputStream(byteArrayOutputStream);
o.writeObject(myobject);
byte [] byteArray=byteArrayOutputStream.toByteArray();
o.flush();
o.close();
byteArrayOutputStream.flush();
byteArrayOutputStream.close();
When objects are converting into byte array with many threads, this conversion takes time more and the time consumption per conversion(same objects into byte array) gets increased gradually. (For example, first thread conversion take 200ms, second thread gets 300ms for the same object conversion) . Can any one let me know why this object conversion time gradually increase and a better way to convert. ( I found a way using Externalization. But then my all objects have to be rewritten with Externalizable.)
toByteArray()a bit early. Remove the last two lines, theo.flush(). And you could donew ByteArrayOutputStream(SIZE).