I am writing Codec to process messages sent over TCP using a protocol based protocol. During the decoding process, I create several String s, BigDecimal and dates. Client-server access patterns mean that the client usually issues a request and then decodes thousands of response messages, resulting in a lot of duplicate String s, BigDecimal s, etc.
So I created an InternPool<T> class that allows me to put every class of an object. Internally, the pool uses WeakHashMap<T, WeakReference<T>> . For example:
InternPool<BigDecimal> pool = new InternPool<BigDecimal>(); ... // Read BigDecimal from in buffer and then intern. BigDecimal quantity = pool.intern(readBigDecimal(in));
My question is: I use InternPool for BigDecimal , but should I use it for the String method instead of String intern() , which I believe uses PermGen space? What is the advantage of using PermGen space?
java garbage-collection permgen string-interning
Adamski
source share