Reputation: 81
I have to transfer some records over TCP though sockets. I used ObjectInputStream
and ObjectOutputStream
and it worked fine. One critical think is that the socket is opened once and has to remain open through the whole communication but each side reads and writes more than once (so it more like a persistent connection).
I tried to compress the Objects before writing them in order to increase the overall performance and the results were quite encouraging but, since I used GZIPOutputStream
and ByteArrayOutputStream
, the memory overhead is too large and in some case I get OutOfMemory error.
I tried DeflaterOutputStream
but it didn't seem apropriate for writting objects.
Is there any way to solve this problem?
Upvotes: 1
Views: 532
Reputation: 10020
Java serialization is convenient, but rather ineffective both size-wise and in CPU usage. If you want high performance, suggest you use a completely different communication protocol, for example based on Protocol Buffers or something else light-weight.
Upvotes: 4