Menu

#2 Test for unnecessary thread-safety

open
nobody
Codechecks (15)
5
2005-09-29
2005-09-29
Bart Buil
No

Test for unnecessary thread-safety

- Category: Optimization

- Bad code:
{
List l = new Vector;
l.add();
}
- Good code:
{
List l = new Arraylist;
For ( ; ; ) {
l.add();
}
}

Discussion

  • Reinier Zwitserloot

    Logged In: YES
    user_id=130807

    Given that Vector and Hashtable are both things that for all
    practical intents and purposes really ought to be given
    @Deprecated tags, replacing them with synchronized variants
    of ArrayList and HashMap using the Collections.
    synchronizedXYZ methods, I suggest approaching this fix from
    that specific angle and call it something like 'treat Vector and
    Hashtable as deprecated' or some such. Possibly go with a
    separate codecheck that checks on synchronizing on local
    objects that are never exported and hence couldn't possibly do
    anything useful from a synchronized() mechanics point of view.

     
  • Reinier Zwitserloot

    Logged In: YES
    user_id=130807

    Hmm, I completely forgot about StringBuilder vs. StringBuffer.
    That would also be a very useful code check. So I guess the
    plan to approach it from the 'consider Vector and HashTable
    deprecated' angle is not going to work.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.