[cdi-dev] Thread safety of SeContainer and SeContainerInitializer

Laird Nelson ljnelson at gmail.com
Thu Jan 5 16:56:07 EST 2017


(Resurrecting this thread.  Happy New Year!)

Another (related) case I had a question about.

Suppose I have the standard SeContainer "block" like this:

try (final SeContainer container = initializer.initialize()) {
  // stuff goes here
}

Inside that block, may I start threads and have them do things with the
container variable?  It sounds like strictly speaking no, I may not—i.e.
that the specification, since it says nothing one way or the other about
threading, therefore implies that only one thread may, say, iterate over
the container (either using its iterator() or stream() methods).

On the other hand, I see no restriction in the specification on the
creation of threads from, say, a managed bean, which means it is always
possible that at any point an Instance object may be used by many threads.
Or, further, since events may be fired asynchronously, then it would *seem* to
follow that iteration over an Instance must be thread safe.

Should the specification include language related to concurrency in these
matters and others?

Best,
Laird

On Thu, Dec 8, 2016 at 1:37 AM Martin Kouba <mkouba at redhat.com> wrote:

> I agree with John, it's not guaranteed. However, the original intention
> (based on Weld SE impl) was:
>
> * SeContainerInitializer is not thread-safe and should not be shared
> between threads
> * it should be safe to call SeContainer.close() from any thread
>
> Martin
>
> Dne 7.12.2016 v 22:01 John Ament napsal(a):
> > I would say that this is not guaranteed.
> >
> >
> >
> > ------------------------------------------------------------------------
> > *From:* cdi-dev-bounces at lists.jboss.org
> > <cdi-dev-bounces at lists.jboss.org> on behalf of Laird Nelson
> > <ljnelson at gmail.com>
> > *Sent:* Wednesday, December 7, 2016 3:56 PM
> > *To:* cdi-dev at lists.jboss.org
> > *Subject:* [cdi-dev] Thread safety of SeContainer and
> > SeContainerInitializer
> >
> > Are SeContainer and SeContainerInitializer safe for concurrent use by
> > multiple threads?  The string "concurren" shows up only four times in
> > the 2.0 specification but not in this context.
> >
> > I'm most interested in whether it is guaranteed that one thread may call
> > SeContainer::initialize and another may call SeContainer::close.
> >
> > I'm assuming that this is /not/ guaranteed.
> >
> > Best,
> > Laird
> > ------------------------------------------------------------------------
> > NOTICE: This e-mail message and any attachments may contain
> > confidential, proprietary, and/or privileged information which should be
> > treated accordingly. If you are not the intended recipient, please
> > notify the sender immediately by return e-mail, delete this message, and
> > destroy all physical and electronic copies. Thank you.
> >
> >
> > _______________________________________________
> > cdi-dev mailing list
> > cdi-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/cdi-dev
> >
> > Note that for all code provided on this list, the provider licenses the
> code under the Apache License, Version 2 (
> http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas
> provided on this list, the provider waives all patent and other
> intellectual property rights inherent in such information.
> >
>
> --
> Martin Kouba
> Software Engineer
> Red Hat, Czech Republic
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20170105/d8f03ac1/attachment.html 


More information about the cdi-dev mailing list