Fixed
Details
Assignee
Yoann RodièreYoann RodièreReporter
Yoann RodièreYoann RodièreComponents
Sprint
NoneFix versions
Priority
Major
Details
Details
Assignee
Yoann Rodière
Yoann RodièreReporter
Yoann Rodière
Yoann RodièreComponents
Sprint
None
Fix versions
Priority
Created May 23, 2018 at 2:06 PM
Updated January 31, 2019 at 3:08 PM
Resolved December 11, 2018 at 6:25 PM
Currently, CDI beans are held in a map, and released on shutdown.
This is not ideal, as some beans may only be used during bootstrap, so we could release them earlier.
One way to solve this would be to make
BridgeBuilder
andBeanResolver
return a "releasable"BeanHolder
, so thatContainedBeans
from CDI/Spring (obtained through Hibernate ORM) can be properly released.This would also allow users to properly release their own CDI beans, for instance those built using an
Instance<MyBridge>
and returned by a customBridgeBuilder
: users would be able to implement aBeanHolder
that callsinstance.destroy( bean )
upon release.Also, the fact that most of or beans extend
AutoCloseable
makes CDI lifecycle a bit confusing: should users add a@PreDestory
method? Should they simply add code to#close()
? Both?I would personally be in favor of removing the
close()
method from user-provided components. I would make the reflection-based bean provider return aCloseableBeanReference
whenever a user bean implementsAutoCloseable
. This reference would just callclose()
whenrelease()
is called, wrapping the exception with aRuntimeException
if necessary.DECISION on the striked-through text above: let's just improve the Javadoc to 1) tell in which order the close() / @PreDestroy-annotated methods will be called and 2) remind users that their close() methods should work correctly even if called twice.