Re: Guarantees around Servlet Filter initialization that sets an instance variable?
Tim Peierls via Concurrency-interest <[email protected]> Wed, 15 Apr 2020 17:12:50 -0400
| Newsgroups | gmane.comp.java.jsr.166-concurrency |
|---|---|
| Message-ID | <CA+F8eeR3akO2c4tXs1g1-2ZpOcW7RYzVZg3Dgf0Q091j+2kH9g@mail.gmail.com> |
I’d be inclined to trust this line in the Javadoc <https://github.com/javaee/servlet-spec/blob/d3d0f3ba4dc9256122f01ebdd4be4fae2a586df3/src/main/java/javax/servlet/Filter.java#L58-L60> : The init method must complete successfully before the filter is asked to do any filtering work. "Complete successfully before" falls short of specifying that there is a *happens-before* edge between the actions in init() and those in doFilter(), but it’s hard to imagine an implementation for which that wouldn't be the case. —tim On Wed, Apr 15, 2020 at 4:46 PM Ludwig, Mark via Concurrency-interest < [email protected]> wrote: > Greetings, > > > > I hope this is a suitable topic for this list. > > > > We are wondering if we need to arrange for some explicit synchronization > in a Servlet Filter’s doFilter() method to safely refer to an instance > variable that was set in the init() method. > > > > We can’t find any mention of this, and without forcing memory fences, are > concerned that we’re asking for trouble downstream somewhere. > > > > (I think this works, consistently, in practice, “by accident,” because > there is enough synchronization required between when the container > instantiates the filter and calls init() in one thread and when the first > doFilter() call comes along in a worker thread. It seems to me that just > having a worker thread pick up a request from a shared queue involves > synchronization that “covers” this need in that thread.) > > > > Thanks, > > > > Mark Ludwig > > > > Siemens Digital Industries Software > > Lifecycle Collaboration > > 5939 Rice Creek Parkway > > Shoreview, MN 55126 United States > > Tel. :+1 (651) 855-6140 > > Fax :+1 (651) 855-6280 > > [email protected] > > > _______________________________________________ > Concurrency-interest mailing list > [email protected] > http://cs.oswego.edu/mailman/listinfo/concurrency-interest > _______________________________________________ Concurrency-interest mailing list [email protected] http://cs.oswego.edu/mailman/listinfo/concurrency-interest