Service Providers lifecycle

View: New views
3 Messages — Rating Filter:   Alert me  

Service Providers lifecycle

by waz-17 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,



I have a question about the lifecycle of Service Providers looked up by Lookup. If an instance does not exist, a new one is created. But if an instance is looked up and discarded, will a future lookup return the same instance? I would like to know if I need to keep references to the Service Providers to avoid them being garbage collected, since they contain some state information.



Many Thanks,

Waz





Re: Service Providers lifecycle

by Jaroslav Tulach :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 27 October 2009 10:20:50 waz wrote:

> Hi,
>
>
>
> I have a question about the lifecycle of Service Providers looked up by
> Lookup. If an instance does not exist, a new one is created. But if an
> instance is looked up and discarded, will a future lookup return the same
> instance? I would like to know if I need to keep references to the Service
> Providers to avoid them being garbage collected, since they contain some
> state information.

Look at openide.util/test/** to see if you use case is covered. As far as I
know the instances are hold by WeakReference. Thus they can be GC if nobody
else except meta-inf services lookup uses them.

-jst

Re: Service Providers lifecycle

by Jesse Glick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jaroslav Tulach wrote:
>> I would like to know if I need to keep references to the Service
>> Providers to avoid them being garbage collected, since they contain some
>> state information.
>
> instances are hold by WeakReference. Thus they can be GC

...and this is by design. Your service instances should not contain state; they should be flyweight objects, there just to implement the service interface. If they need
to persist some data, use static fields, an external singleton class, whatever.