You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@any23.apache.org by Simone Tripodi <si...@apache.org> on 2013/02/02 11:28:54 UTC

Re: svn commit: r1441675 - /any23/trunk/api/src/main/java/org/apache/any23/vocab/

Hi Lewis!

please apologise in advance my lack of knowledge on that topic, I have
some minor observations about the code style:

>     any23/trunk/api/src/main/java/org/apache/any23/vocab/LKIF_CORE_ACTION.java

in my humble opinion, this way of naming classes is a little
confusing, since usually it is referred to static constants, I would
replace them with `LkifCoreAction`.
Keep it jut as my opinion, anyway ;)

> +    public static DOAP getInstance() {
>          if(instance == null) {
>              instance = new DOAP();
>          }
>          return instance;
>      }

this pattern is not thread safety, immagine 2 (or more) threads access
to `getInstance()` method simultaneously, `instance` would be
initialised more than once; we have 2 options:

 * initialise `instance` by default;

or, if you want to keep the lazy initialisation:

 * synchronise all `getInstance()` methods.

HTH, have a nice day!
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/

Re: svn commit: r1441675 - /any23/trunk/api/src/main/java/org/apache/any23/vocab/

Posted by Peter Ansell <an...@gmail.com>.
On 2 February 2013 21:20, Simone Tripodi <si...@apache.org> wrote:
>> As far as I know, it is not vital for there to be a single instance
>> for OpenRDF URIs, as equality for URIs is not object equality.
>> Therefore, it should not matter whether there are two or more copies
>> of the "instance" available as equality is preserved for the multiple
>> objects that would be created.
>>
>
> so what's the advantage to have such `getInstance()` method? just make
> the constructor public and instantiate it :)

I only use premade/late-bound-single instances for performance
benefits myself, so it could just be that. Not sure why they
constructor could not be public in this case.

Cheers,

Peter

Re: svn commit: r1441675 - /any23/trunk/api/src/main/java/org/apache/any23/vocab/

Posted by Simone Tripodi <si...@apache.org>.
> As far as I know, it is not vital for there to be a single instance
> for OpenRDF URIs, as equality for URIs is not object equality.
> Therefore, it should not matter whether there are two or more copies
> of the "instance" available as equality is preserved for the multiple
> objects that would be created.
>

so what's the advantage to have such `getInstance()` method? just make
the constructor public and instantiate it :)

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/

Re: svn commit: r1441675 - /any23/trunk/api/src/main/java/org/apache/any23/vocab/

Posted by Peter Ansell <an...@gmail.com>.
On 2 February 2013 20:28, Simone Tripodi <si...@apache.org> wrote:
> Hi Lewis!
>
> please apologise in advance my lack of knowledge on that topic, I have
> some minor observations about the code style:
>
>>     any23/trunk/api/src/main/java/org/apache/any23/vocab/LKIF_CORE_ACTION.java
>
> in my humble opinion, this way of naming classes is a little
> confusing, since usually it is referred to static constants, I would
> replace them with `LkifCoreAction`.
> Keep it jut as my opinion, anyway ;)
>
>> +    public static DOAP getInstance() {
>>          if(instance == null) {
>>              instance = new DOAP();
>>          }
>>          return instance;
>>      }
>
> this pattern is not thread safety, immagine 2 (or more) threads access
> to `getInstance()` method simultaneously, `instance` would be
> initialised more than once; we have 2 options:
>
>  * initialise `instance` by default;
>
> or, if you want to keep the lazy initialisation:
>
>  * synchronise all `getInstance()` methods.

As far as I know, it is not vital for there to be a single instance
for OpenRDF URIs, as equality for URIs is not object equality.
Therefore, it should not matter whether there are two or more copies
of the "instance" available as equality is preserved for the multiple
objects that would be created.

The current pattern provides late initialisation, without requiring
synchronisation which would slow down the application without cause.

Cheers,

Peter