users@glassfish.java.net

Re: Curious about this -- any explanation?

From: Craig Ringer <craig_at_postnewspapers.com.au>
Date: Thu, 07 Oct 2010 16:06:31 +0800

On 10/06/2010 11:26 AM, Sivakumar Thyagarajan wrote:

> To add more information to why the constructor is executed twice for
> normal-scoped CDI beans, please also see the discussion at [1]
>
> Thanks
> --Siva.
> [1]
> http://weld-development-discussions.46994.n3.nabble.com/Bean-created-twice-tt987853.html#a994358
> and http://www.seamframework.org/Community/BeanCreatedTwice

Ugh. Does that that effectively prevent the use of final members in
classes used with CDI? Such final members must be initialized by the
ctor or direct assignment at the declaration site, they can't be
initialized in @PostConstruct. Yet apparently that'll cause multiple
evaluation of their definitions due to the multiple construction. How
does that work?

It sounds to me a lot like CDI needs some help from the JVM to be able
to cleanly proxy objects before their ctors are called, so this mess
with @PostConstruct and multiple constructor calls goes away. I knew
injection might not have been performed when the ctor is called, but the
ctor being called twice is news to me, and doesn't seem to be covered in
any of the documentation I've read on all this so far.

--
Craig Ringer