Yes, you need to do something to hold a strong reference to the coordination. But you also need to make sure you always clean up so there is no case where a strong reference is never cleaned up. I don't know anything about your use case.
--
BJ Hargrave
Senior Technical Staff Member, IBM // office: +1 386 848 1781
OSGi Fellow and CTO of the OSGi Alliance // mobile: +1 386 848 3788
hargr...@us.ibm.com
BJ Hargrave
Senior Technical Staff Member, IBM // office: +1 386 848 1781
OSGi Fellow and CTO of the OSGi Alliance // mobile: +1 386 848 3788
hargr...@us.ibm.com
----- Original message -----
From: Christian Schneider <ch...@die-schneider.net>
Sent by: osgi-dev-boun...@mail.osgi.org
To: OSGi Developer Mail List <osgi-dev@mail.osgi.org>
Cc:
Subject: Re: [osgi-dev] Valid coordinator scenario?
Date: Mon, Aug 3, 2015 5:11 PM
So what is the preferred solution for my use case?
I will need to push the coorrdination on the stack as this is the only way for other modules on the thread to find it.
Pop seems to be a bad idea because of the problem of maybe getting a different coordination.
So if I know my code is only called once on this thread I should be able to use a simple thread local:
ThreadLocal<Coordination> coordination;
In my interceptor before the user code:
coordination.set(coordinator.begin());
In my interceptor after the user code:
coordination.get().end();
If the code can be called more than once per thread I would need to use a Stack.
Does that make sense?
Christian
On 03.08.2015 22:00, BJ Hargrave wrote:In that code snippet, the call to gc() is stand in for other code which could trigger a gc. And it is also possible that this other code alters the coordination stack (fails the coordination; coordination times out; ...), so the pop() call may not return the coordination began in the first line.So one really does need to keep the began coordination in a local variable to ensure you are attempting to end the same coordination you began. That is, the code snippet is broken in multiple ways.--
BJ Hargrave
Senior Technical Staff Member, IBM // office: +1 386 848 1781
OSGi Fellow and CTO of the OSGi Alliance // mobile: +1 386 848 3788
hargr...@us.ibm.com_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev