Berin Loritsch a écrit :
>
> Torsten Curdt wrote:
> >
> > Hi, that's exactly what I was wondering, too
> >
> > > > Hi,
> > > >
> > > > I just wanted to make a SingleThreaded component poolable. Is this
> > > > not allowed?
> > >
> > > They are not allowed. Currently SingleThreaded marks interfaces that
> > > cannot be reused, and must be used in one thread at a time. Therefore,
> > > they are manufactured by the Factory method.
> >
> > But why?! I have a component that is not ThreadSafe (and therefor I would
> > like to declare it SingleThreaded. But it since it is just a helper component
> > and there is no need to create new instances all the time I'd like to
> > make it Rececylable (extends Poolable)
> >
> > What is wrong with this approach?
>
> If it can be reused, then make it Recyclable--that implcitly makes the component
> Poolable. There is not problem with that approach. However, if for reasons
> beyond _your_ control the component cannot be reused you must use the SingleThreaded
> interface.
>
> > > Poolable components (inherently only run in one thread at a time) can
> >
> > So Poolable should extend SingleThreaded ?!
>
> Theorhetically, this may be true. Poolable is a special case of a component
> that must be single threaded. However, the SingleThreaded concept is familiar
> to Servlet writers who use the variation of the Servlet that forces a new copy
> to be created for each request--or serialize all accesses to it so only one
> thread accesses it at a time. Clearly not optimal--though sometimes necessary.
>
> >
> > > be reused, therefore when one thread is done with it, it is returned
> > > to the pool.
> > --
> > Torsten
> >
I also questioned myself about the relationship between SingleThreaded
and Poolable. A poolable object is one that isn't ThreadSafe and whose
creation cost (instantiation and initialization) justify to keep created
instances in the pool for later reuse instead of throwing them to
garbage.
Forbidding SingleThreaded _and_ Poolable means you cannot have a simple
stateful component implementation marked SingleThreaded and a subclass
of it marked Poolable, while both are equally not ThreadSafe.
So, IMO, this greatly limits the usefullness of SingleThreaded : people
won't use it because it's equivalent to having no lifestyle marker, but
forbids Poolable subclasses. We should be able to use SingleThreaded to
strongly mark classes that _cannot_ be made ThreadSafe by subclassing
them, without any assumption on poolable/not poolable.
--
Sylvain Wallez
Anyware Technologies - http://www.anyware-tech.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]