oghenez / mycila

Automatically exported from code.google.com/p/mycila
0 stars 0 forks source link

JSR250 @PreDestroy is not invoked in dependency order #32

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Singletons are destroyed in the order they are bound. They should be destroyed 
in reverse instantiation order.

I've created a failing test case http://pastie.org/2213224

I'm not aware of a quick quick workaround, the implementation would have to 
change quite a bit to fix it.

What do you think of this alternative approach? A TypeListener that looks for 
singletons and puts them in a list, which will naturally be in instantiation 
order and then destroying them by iterating this list backwards. The list would 
need to be synchronized, and its important that its synchronized in concert 
with the synchronization in Guice for creating singletons so not to create a 
race condition into adding to this list. Also it might be necessary to have 
weak references in this list instead of real references.

// Tobias

Original issue reported on code.google.com by totobobi...@gmail.com on 14 Jul 2011 at 4:30

GoogleCodeExporter commented 8 years ago
I have also encountered this problem. I have a class Room which is injected 
with a class Connection. When destroying, the room has to be deleted before the 
connection is closed, which would happen if preDestroy used 
reverse-instantiation order, but currently the Connection is closed before the 
Room is deleted.

Original comment by flamingp...@gmail.com on 1 Aug 2011 at 3:15

GoogleCodeExporter commented 8 years ago

Original comment by mathieu....@gmail.com on 7 Aug 2011 at 7:22

GoogleCodeExporter commented 8 years ago

Original comment by mathieu....@gmail.com on 7 Aug 2011 at 7:45