Generate Java Externalizable readExternal () / writeExternal () automatically

I'm working on a project where traditional Java serialization is slow, so we want to move on to implementing the Externalize interface for classes to provide superior performance.

However, these classes have many data members, and we realized that it is easy to make mistakes when writing these two methods. We just read / write all members of the class into these functions, nothing unusual. Is there a way to generate readExternal() writeExternal() blocks for emergency automation offline or at compile time?

I looked at http://projectlombok.org/ and something like that would be perfect.

Similarly, we would like to keep these classes immutable, but immutable classes cannot implement an interface that can be replaced - we want to use the proxy class template from efficient java, since the generated one will be useful.

+8
java serialization lombok code-generation
source share
1 answer

I am working on a project where native Java serialization is slow

How slow? What for? Making it faster with a lot of manual coding is unlikely to be economically viable or supported in the long run. The serialization overhead should really decrease in time and space during transmission. There is no particular reason why default Java serialization should be strikingly slower than the result of all the manual encoding you plan on. You will be better off exploring the causes. For example, you may find that a well-chosen BufferedOutputStream will solve all your problems.

+1
source share

All Articles