db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-4723) Using an instance lock to protect static shared data in EmbedPooledConnection
Date Tue, 29 Jun 2010 11:05:50 GMT

    [ https://issues.apache.org/jira/browse/DERBY-4723?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12883509#action_12883509
] 

Knut Anders Hatlen commented on DERBY-4723:
-------------------------------------------

I agree that Wendy's proposed fix sounds fine.

Since the field is only used to identify the instance uniquely in toString(), and toString()
already prints the value of Object.hashCode(), perhaps we could just remove this code? Object.hashCode()
isn't guaranteed to return a unique value, but it's probably good enough for tracing purposes.

> Using an instance lock to protect static shared data in EmbedPooledConnection
> -----------------------------------------------------------------------------
>
>                 Key: DERBY-4723
>                 URL: https://issues.apache.org/jira/browse/DERBY-4723
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions: 10.5.1.1
>            Reporter: Wendy Feng
>            Priority: Minor
>   Original Estimate: 0.17h
>  Remaining Estimate: 0.17h
>
> EmbedPooledConnection has the unsafe synchronization as follow.
>  
> private static int idCounter = 0;
> private synchronized int nextId()
>     {
>         return idCounter++;
>     }
> idCounter is a static shared data, and it is not proper to use a instance lock to protect
it, especially when two instance of the class are created.
> it would be more safer to write this instead:
> private static synchronized int nextId()
>     {
>         return idCounter++;
>     }

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


Mime
View raw message