jsr369-experts@servlet-spec.java.net

[jsr369-experts] Re: Subject: [81-ClarifyThreadRequirementsOnInit] DISCUSSION

From: Edward Burns <edward.burns_at_oracle.com>
Date: Thu, 23 Mar 2017 16:44:51 -0700

>>>>> On Wed, 22 Mar 2017 09:11:04 +1100, Stuart Douglas <sdouglas_at_redhat.com> said:

SD> I think we should go with Option Container, it would very much
SD> surprise me if any containers did not already do this.

SD> In practice the code that stops service() being called before init()
SD> is complete should be a sufficient memory barrier to make sure that
SD> the changes in init() are visible. Off the top of my head I can't
SD> think of a way to implement this such that the changes are not
SD> guaranteed to be visible without also opening up the possibility of
SD> init() and service() being active at the same time.

>>>>> On Tue, 21 Mar 2017 22:11:14 +0000, Mark Thomas <markt_at_apache.org> said:

MT> I prefer Option Container. This is the behaviour users tend to assume
MT> and it is going to be less work (overall) to fix this in a handful of
MT> containers than in every Servlet.

Thanks Mark and Stuart for your prompt responses. I'm hesitant to
introduce new locking requirements at this point in our implementation
histories. For this reason, I'm going to take option Container off the
table and restate the other two options with alternate text. I recommend
we take option ServletAuthor. Note that I'm removing any explicit
reference to the ServletConfig object.

Option WONTFIX:

  We simply punt on this issue and mark it as WONTFIX. We point out
  that this is precisely the sort of thing the volatile keyword is
  for. [1]

Option ServletAuthor:

  I propose we take the easy way out here and add the following text to
  Servlet#init():

    Servlet Developers must make adequate provisions for the visibility
    of shared variables (as defined in 17.4.1 of the Java Language
    Specification) written to in the init() method and read from in the
    service() method (or any of its convenience methods). For example,
    the volatile keyword could be applied to any instance variables
    written to during init() and read from during service().

  And the following sentence after the sentence in 2.3.3.1. New text in
  **.

  2.3.3.1 Multithreading Issues

  A servlet container may send concurrent requests through the service
  method of the servlet. To handle the requests, the Servlet Developer
  must make adequate provisions for concurrent processing with multiple
  threads in the service method. **Servlet Developers must make
  adequate provisions for the visibility of shared variables (as defined
  in 17.4.1 of the Java Language Specification) written to in the init()
  method and read from in the service() method (or any of its
  convenience methods). For example, the volatile keyword could be
  applied to any instance variables written to during init() and read
  from during service().**

Thanks,

Ed

-- 
| edward.burns_at_oracle.com | office: +1 407 458 0017
|  3 business days until JavaLand 2017
| 21 business days until planned start of Servlet 4.0 Public Review
[1] http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.1.4