You need to show where the getInstance() method is called. Since you don't
call it from your start() or stop() method, I suspect you must be calling
it from another bundle or a thread. Both of these could cause the old
version to be pinned in memory; meaning you will have both the old and new
versions loaded simultaneously.




On Sun, Feb 3, 2013 at 4:49 PM, Erwin Hogeweg <
[email protected]> wrote:

> Hi,
>
> I ran into an issue after I updated a bundle. After some digging I found
> that a static variable didn't have the expected value after the update. I
> have a feel for what is going on, but I can't quite connect all the dots.
>
> So here is what's happening:
>
> I have an Activator with a static self.
>
> public Activator(...){
> private static Activator self;
> ...
> public void start(...){
> self = this;
> ...
> }
>
> public void stop(...){
> self = null;
> ...}
>
> public static Activator getInstance(){
> return self;
> }
>
> When the framework starts up, everything works as expected. When the
> bundle that contains this activator is updated though, the returned value
> for self = null. When I remove the null assignment in the stop() method,
> the getInstance() method returns the self reference from before the bundle
> update. So somehow, the framework holds on to the initial Activator class,
> and keeps using this 'old' reference, even when the getInstance() call is
> made from within the bundle itself.
>
> When I inspect the classloader inside the getInstance() method it shows
> the same reference before and after the update, which is suspicious, and
> probably the cause of the problem.
>
> I am not necessarily looking for a solution because there is a better way
> to solve this problem, but I would like to understand exactly what is going
> here. I don't quite get it yet.
>
> Any insight is highly appreciated.
>
> Kind Regards,
>
> Erwin
>
>
> _______________________________________________
> OSGi Developer Mail List
> [email protected]
> https://mail.osgi.org/mailman/listinfo/osgi-dev
>
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to