commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles (JIRA)" <>
Subject [jira] [Commented] (MATH-757) ResizableDoubleArray is not thread-safe yet has some synch. methods
Date Tue, 23 Oct 2012 12:37:11 GMT


Gilles commented on MATH-757:

I find the "addElement" method a little strange:
public synchronized void addElement(double value) {
  if ((startIndex + numElements) > internalArray.length) {
  internalArray[startIndex + (numElements - 1)] = value;
  if (shouldContract()) {

Why would we want to contract just after _adding_ an element?
This seems to be arguably useful only if the "initial capacity" was not set correctly. In
fact, the current code always contracts the array (created with the default constructor) at
the first call to "addElement" because the default initial capacity (16) is "too large" for
an array that contains a single element...

The method would also probably be slightly more efficient if written as:
public synchronized void addElement(double value) {
  if (internalArray.length <= startIndex + numElements) {
  internalArray[startIndex + numElements++] = value;

> ResizableDoubleArray is not thread-safe yet has some synch. methods
> -------------------------------------------------------------------
>                 Key: MATH-757
>                 URL:
>             Project: Commons Math
>          Issue Type: Bug
>            Reporter: Sebb
>             Fix For: 3.1
> ResizableDoubleArray has several synchronised methods, but is not thread-safe, because
class variables are not always accessed using the lock.
> Is the class supposed to be thread-safe?
> If so, all accesses (read and write) need to be synch.
> If not, the synch. qualifiers could be dropped.
> In any case, the protected fields need to be made private.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message