Recommended way of decoding non-framed messages?

tsuna tsunanet at gmail.com
Sun Aug 1 20:12:19 EDT 2010


On Sun, Aug 1, 2010 at 4:48 PM, brunodecarvalho <kindernade at gmail.com> wrote:
> You can find the source code for netty here:
> http://docs.jboss.org/netty/3.2/xref/

Yeah I downloaded it and read it extensively for a few weeks already :)

> Regarding the paragraph you quoted from JLS, do you have any idea as to why
> it is "prohibitively expensive" to store the stack trace?

Yeah, I understand their point, and it seemed to contradict Netty's javadoc.

> I've used Exception-as-constant approach only one or two times before (much
> like ChannelFuture's CANCELLED exception,
> http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/channel/DefaultChannelFuture.html#45)
> and running a couple of tests now I found out that this exception will
> always store the stack trace of the code that initialized it or called it
> for the first time (either to be thrown or returned).
>
> So if this Exception-constant is called from a long stack the first time,
> that stack will be preserved. If, on the other hand, some static
> initialization code takes care of initializing it (throwing it or just call
> something like .getClass() on the constant) the stored stack will be rather
> small (and - I supposed - occupy less memory).

So this isn't so much that "throwing an Error" is cheaper (as the
javadoc implied), since what you're describing holds true for regular
Exceptions too.  I thought the claim in the javadoc was that Error was
subject to some kind of a special treatment that made it cheaper,
which is what surprised me.  I guess the javadoc's wording is
misleading.

-- 
Benoit "tsuna" Sigoure
Software Engineer @ www.StumbleUpon.com


More information about the netty-users mailing list