tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrei Ivanov <andrei.iva...@gmail.com>
Subject Re: svn commit: r1825978 - /tomcat/trunk/java/org/apache/catalina/security/SecurityConfig.java
Date Tue, 06 Mar 2018 13:26:24 GMT
On Tue, Mar 6, 2018 at 1:32 PM, <markt@apache.org> wrote:

> Author: markt
> Date: Tue Mar  6 11:32:42 2018
> New Revision: 1825978
>
> URL: http://svn.apache.org/viewvc?rev=1825978&view=rev
> Log:
> SpotBugs
> Correctly construct singleton in a thread-safe manner
>
> Modified:
>     tomcat/trunk/java/org/apache/catalina/security/SecurityConfig.java
>
> Modified: tomcat/trunk/java/org/apache/catalina/security/
> SecurityConfig.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/
> catalina/security/SecurityConfig.java?rev=1825978&r1=1825977&r2=1825978&
> view=diff
> ============================================================
> ==================
> --- tomcat/trunk/java/org/apache/catalina/security/SecurityConfig.java
> (original)
> +++ tomcat/trunk/java/org/apache/catalina/security/SecurityConfig.java
> Tue Mar  6 11:32:42 2018
> @@ -28,7 +28,9 @@ import org.apache.juli.logging.LogFactor
>   * @author the Catalina.java authors
>   */
>  public final class SecurityConfig{
> -    private static SecurityConfig singleton = null;
> +
> +    private static final Object singeltonLock = new Object();
> +    private static volatile SecurityConfig singleton = null;
>
>      private static final Log log = LogFactory.getLog(
> SecurityConfig.class);
>
> @@ -83,8 +85,12 @@ public final class SecurityConfig{
>       * @return an instance of that class.
>       */
>      public static SecurityConfig newInstance(){
> -        if (singleton == null){
> -            singleton = new SecurityConfig();
> +        if (singleton == null) {
> +            synchronized (singeltonLock) {
> +                if (singleton == null) {
> +                    singleton = new SecurityConfig();
> +                }
> +            }
>          }
>          return singleton;
>      }
>

Hi,
There's a typo on singeltonLock.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message