[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2928) optimizers for enhanced id generators should be synchronized against multi-threaded access

Maciej Baranowski (JIRA) noreply at atlassian.com
Wed Dec 12 14:06:56 EST 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29146 ] 

Maciej Baranowski commented on HHH-2928:
----------------------------------------

Here is a fixed version of NoopOptimizer generate() method. As you may notice the trick is to use a local method variable. This is better then adding the synchronized clause for the whole method - as this would cause scalability problems in the case when there is latency on database connection.

    public Serializable generate(AccessCallback callback) {

            //copy the value to local variable to avoid race condition
            long localLastSourceValue = lastSourceValue;

            if (localLastSourceValue == -1) {
                while (localLastSourceValue <= 0) {
                    localLastSourceValue = callback.getNextValue();
                }
            } else {
                localLastSourceValue = callback.getNextValue();
            }

            lastSourceValue = localLastSourceValue;

            return make(localLastSourceValue);
        }

Sorry that it is not a formal patch but I am not sure what version of the OptimizerFactory it should apply to

> optimizers for enhanced id generators should be synchronized against multi-threaded access
> ------------------------------------------------------------------------------------------
>
>                 Key: HHH-2928
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2928
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.5
>            Reporter: Steve Ebersole
>            Assignee: Steve Ebersole
>             Fix For: 3.2.6, 3.3
>
>         Attachments: NoopOptimizerTest.java, NoopOptimizerTest.java, NoopRaceConditionTest.java
>
>
> Currently the optimizers do not serialize access to their internal state when applying their optimizations.  This only affects the pooled and hilo optimizers.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list