Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Java Externalizable readExternal() / writeExternal() blocks automatically

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

However, these classes have lots of data members, and we have realized its easy to make mistakes while writing these two methods. We are just reading/writing all of the members of the class in these functions, nothing fancy. Is there some way of generating the readExternal() writeExternal() blocks for externalize automatically in an offline process, or at compile time?

I had a look at http://projectlombok.org/, and something like that would have been ideal.

Similarly, we would like to keep these classes immutable, but immutable classes can not implement the externalizable interface - we want to use the proxy class pattern from effective java - having that generated would be useful too.

like image 710
MrLebowski Avatar asked Aug 16 '11 22:08

MrLebowski


1 Answers

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

How slow? Why? Making it faster with lots of hand coding is most unlikely to be either economically feasible or maintainable in the long run. Serialization overheads should really come down to time and space bounds in transmisssion. There's no particular reason why Java's default serialziation should be startlingly slower than the result of all the hand coding you are planning. You would be better off investigating causes. You might find for example that a well-placed BufferedOutputStream would solve all your problems.

like image 56
user207421 Avatar answered Sep 28 '22 02:09

user207421