You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Hanson Char (JIRA)" <ji...@apache.org> on 2007/04/20 07:29:15 UTC

[jira] Created: (LANG-329) Pointless synchronized in ThreadLocal.initialValue should be removed

Pointless synchronized in ThreadLocal.initialValue should be removed
--------------------------------------------------------------------

                 Key: LANG-329
                 URL: https://issues.apache.org/jira/browse/LANG-329
             Project: Commons Lang
          Issue Type: Improvement
    Affects Versions: 2.3
         Environment: Any
            Reporter: Hanson Char
            Priority: Trivial


--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/01/27 07:13:59	500497
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/04/20 05:06:03	530645
@@ -103,7 +103,7 @@
      * </p>
      */
     private static ThreadLocal registry = new ThreadLocal() {
-        protected synchronized Object initialValue() {
+        protected Object initialValue() {
             // The HashSet implementation is not synchronized,
             // which is just what we need here.
             return new HashSet();

--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2006/09/19 21:58:11	447989
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2007/04/20 05:11:46	530648
@@ -103,7 +103,7 @@
      * @since 2.3
      */
     private static ThreadLocal registry = new ThreadLocal() {
-        protected synchronized Object initialValue() {
+        protected Object initialValue() {
             // The HashSet implementation is not synchronized,
             // which is just what we need here.
             return new HashSet();



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Resolved: (LANG-329) Pointless synchronized in ThreadLocal.initialValue should be removed

Posted by "Hanson Char (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-329?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hanson Char resolved LANG-329.
------------------------------

    Resolution: Fixed

I've fixed it in the SVN main trunk.  Let me know if any problem.  Thanks.

> Pointless synchronized in ThreadLocal.initialValue should be removed
> --------------------------------------------------------------------
>
>                 Key: LANG-329
>                 URL: https://issues.apache.org/jira/browse/LANG-329
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.3
>         Environment: Any
>            Reporter: Hanson Char
>            Priority: Trivial
>
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/01/27 07:13:59	500497
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/04/20 05:06:03	530645
> @@ -103,7 +103,7 @@
>       * </p>
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2006/09/19 21:58:11	447989
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2007/04/20 05:11:46	530648
> @@ -103,7 +103,7 @@
>       * @since 2.3
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (LANG-329) Pointless synchronized in ThreadLocal.initialValue should be removed

Posted by "Hanson Char (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-329?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12490380 ] 

Hanson Char commented on LANG-329:
----------------------------------

The reason is in this case the returned instance is a new instance every time.  There is shared state.  Synchronization is required only if a shared object is accessed, like the examples of read-modify-write integer increment they gave in the javadoc.

Also, I've verified if this case is pointless or not in the jsr166 concurrency forum.  See http://www.nabble.com/forum/ViewPost.jtp?post=10089323&framed=y

> Pointless synchronized in ThreadLocal.initialValue should be removed
> --------------------------------------------------------------------
>
>                 Key: LANG-329
>                 URL: https://issues.apache.org/jira/browse/LANG-329
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.3
>         Environment: Any
>            Reporter: Hanson Char
>            Priority: Trivial
>             Fix For: 3.0
>
>
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/01/27 07:13:59	500497
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/04/20 05:06:03	530645
> @@ -103,7 +103,7 @@
>       * </p>
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2006/09/19 21:58:11	447989
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2007/04/20 05:11:46	530648
> @@ -103,7 +103,7 @@
>       * @since 2.3
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (LANG-329) Pointless synchronized in ThreadLocal.initialValue should be removed

Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-329?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12490375 ] 

Gary Gregory commented on LANG-329:
-----------------------------------

Before we sign off on this I'd like to know why it is "pointless" and why does Sun recommend doing it the way the code was before this patch in their documentation.

Please see:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ThreadLocal.html
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ThreadLocal.html

If you are on 1.6+, you'd do it differently:
http://java.sun.com/javase/6/docs/api/java/lang/ThreadLocal.html


> Pointless synchronized in ThreadLocal.initialValue should be removed
> --------------------------------------------------------------------
>
>                 Key: LANG-329
>                 URL: https://issues.apache.org/jira/browse/LANG-329
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.3
>         Environment: Any
>            Reporter: Hanson Char
>            Priority: Trivial
>             Fix For: 3.0
>
>
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/01/27 07:13:59	500497
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/04/20 05:06:03	530645
> @@ -103,7 +103,7 @@
>       * </p>
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2006/09/19 21:58:11	447989
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2007/04/20 05:11:46	530648
> @@ -103,7 +103,7 @@
>       * @since 2.3
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (LANG-329) Pointless synchronized in ThreadLocal.initialValue should be removed

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-329?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-329:
-------------------------------

    Fix Version/s: 3.0

No major problems. Minor ones:

* Set a fix version in JIRA to the next planned version. I'm doing that now (3.0).
* Common to introduce yourself if people aren't expecting you to be committing to a component.
* Also somewhat common I think to lag things between the report and the commit to allow for comments, though no biggy.

This looks like a fine fix to me.

> Pointless synchronized in ThreadLocal.initialValue should be removed
> --------------------------------------------------------------------
>
>                 Key: LANG-329
>                 URL: https://issues.apache.org/jira/browse/LANG-329
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.3
>         Environment: Any
>            Reporter: Hanson Char
>            Priority: Trivial
>             Fix For: 3.0
>
>
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/01/27 07:13:59	500497
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/04/20 05:06:03	530645
> @@ -103,7 +103,7 @@
>       * </p>
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2006/09/19 21:58:11	447989
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2007/04/20 05:11:46	530648
> @@ -103,7 +103,7 @@
>       * @since 2.3
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (LANG-329) Pointless synchronized in ThreadLocal.initialValue should be removed

Posted by "Hanson Char (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-329?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12490381 ] 

Hanson Char commented on LANG-329:
----------------------------------

%s/There is shared state/There is no shared state/g

> Pointless synchronized in ThreadLocal.initialValue should be removed
> --------------------------------------------------------------------
>
>                 Key: LANG-329
>                 URL: https://issues.apache.org/jira/browse/LANG-329
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.3
>         Environment: Any
>            Reporter: Hanson Char
>            Priority: Trivial
>             Fix For: 3.0
>
>
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/01/27 07:13:59	500497
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/04/20 05:06:03	530645
> @@ -103,7 +103,7 @@
>       * </p>
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2006/09/19 21:58:11	447989
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2007/04/20 05:11:46	530648
> @@ -103,7 +103,7 @@
>       * @since 2.3
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (LANG-329) Pointless synchronized in ThreadLocal.initialValue should be removed

Posted by "Hanson Char (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-329?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12490371 ] 

Hanson Char commented on LANG-329:
----------------------------------

Will do the right thing next time.  Thanks for the advise.  


> Pointless synchronized in ThreadLocal.initialValue should be removed
> --------------------------------------------------------------------
>
>                 Key: LANG-329
>                 URL: https://issues.apache.org/jira/browse/LANG-329
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.3
>         Environment: Any
>            Reporter: Hanson Char
>            Priority: Trivial
>             Fix For: 3.0
>
>
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/01/27 07:13:59	500497
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringStyle.java	2007/04/20 05:06:03	530645
> @@ -103,7 +103,7 @@
>       * </p>
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();
> --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2006/09/19 21:58:11	447989
> +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java	2007/04/20 05:11:46	530648
> @@ -103,7 +103,7 @@
>       * @since 2.3
>       */
>      private static ThreadLocal registry = new ThreadLocal() {
> -        protected synchronized Object initialValue() {
> +        protected Object initialValue() {
>              // The HashSet implementation is not synchronized,
>              // which is just what we need here.
>              return new HashSet();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org