ambari-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jonathan Hurley (JIRA)" <>
Subject [jira] [Updated] (AMBARI-19364) Investigate Changing the Default Container Policy in JPA From Vector to ArrayList
Date Wed, 04 Jan 2017 17:01:01 GMT


Jonathan Hurley updated AMBARI-19364:
    Attachment: AMBARI-19364.patch

> Investigate Changing the Default Container Policy in JPA From Vector to ArrayList
> ---------------------------------------------------------------------------------
>                 Key: AMBARI-19364
>                 URL:
>             Project: Ambari
>          Issue Type: Task
>          Components: ambari-server
>    Affects Versions: 2.5.0
>            Reporter: Jonathan Hurley
>            Assignee: Jonathan Hurley
>             Fix For: 2.5.0
>         Attachments: AMBARI-19364.patch
> Recently I noticed that collections coming back from JPA were using a {{Vector}} as their
concrete collection. This seems very wrong as {{Vector}} is a completely synchronized collection.

> Tracing through EclipseLink, it seems like this really only affects [ReadAllQuery|].
Essentially, EclipseLink uses  a [ContainerPolicy|]
to determine how the result set should be collected. There are policies for {{Vector}}, {{ArrayList}},
{{HashSet}}, etc. 
> The interesting part here is that this really only affects the {{ReadAllQuery}} which
is used by JPA's {{Query#getResultList()}} ... anytime it needs to create a collection of
entities, it's going to use a {{Vector}}.
> There's actually very little documentation on this. In fact, the only way to change this
is either set a global value for the default container policy, or set a per-query policy.
An example of setting the global policy would be:
> {code}
> public class EclipseLinkSessionCustomizer implements SessionCustomizer {
>   /**
>    * {@inheritDoc}
>    * <p/>
>    * This class exists for quick customization purposes.
>    */
>   @Override
>   public void customize(Session session) throws Exception {
>     // ensure db behavior is same as shared cache
>     DatabaseLogin databaseLogin = (DatabaseLogin) session.getDatasourceLogin();
>     databaseLogin.setTransactionIsolation(DatabaseLogin.TRANSACTION_READ_COMMITTED);
>     // for some reason, read-all queries use a Vector as their container for
>     // result items - this seems like an unnecessary performance hit since
>     // Vectors are synchronized and there's no apparent reason to provide a
>     // thread-safe collection on a read all query
>     ContainerPolicy.setDefaultContainerClass(CoreClassConstants.ArrayList_class);
>   }
> }
> {code}
> This indeed causes collections returned by queries to be backed by ArrayLists. 
> There is some discussion on this topic already:
> It seems like this was kept as a {{Vector}} purely for backward compatibility reasons.

This message was sent by Atlassian JIRA

View raw message