• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Why the performance is improved in these ways?

 
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Jack
I am interesting in this topic that I had related experience to tone the oracle database performance and get the unexpected result,the running process result was faster than I think.
I wonder if you can tell me
Why some people claim?

"Don't use Vector, use ArrayList, it's more efficient." "Don't concatenate Strings, use a StringBuffer, it's more efficient."


And

Basic data structures {String, Linked List...} that was anywhere from 10-50% faster than the JDK implementation


Are there anything involved the peer that is not written by Java code?
thanks
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by siu chung man:
Why some people claim?
quote:
--------------------------------------------------------------------------------
"Don't use Vector, use ArrayList, it's more efficient." "Don't concatenate Strings, use a StringBuffer, it's more efficient."
--------------------------------------------------------------------------------


Because Vector is synchronized, whereas ArrayList isn't. With JDK1.4, synchronization performance improved a bit as far as I know, so it isn't that relevant any longer.

"Don't concatenate Strings, use a StringBuffer, it's more efficient."


See the later messages in this thread.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember though that performance is only one reason to prefer ArrayList to Vector - not the only one, or the best one. The biggest reason Peter den Haan and I detest them is because even if you do need synchronization, Vector typically has it at the wrong level to be of use to you. E.g. you often need a synchronized block that spas several different conseutive uses of the Vector so they can't be interrupted; synhronizing individual methods is pointless here, and just serves to give a false sense of security. "Of course it's thread-safe - Vector is snchronized!" :roll: Hardly.
Also, the method and class names for the legacy collections are generally too long and/or poorly chosen. "Vector" gives no clue what the class does, unless you already come from a CS background. "Hashtable" isn't properly capitalized. And why use "getElement(int)" when you can say "get(int)"? Basically, Vectors and Hashtables offer no features that aren't available in the newer collections, and they have a number of annoying problems. There's just no reason to use the damn things anymore unless you have to interface with other code that uses them.
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Ilja and Jim
Ilja
I have seen the later messages which is very useful for me to understand why use StringBuffer in some situation.
Jim
After I read your answer, two questions arise in my brain.

"Of course it's thread-safe - Vector is snchronized!"


In the security aspect,Is Vector better than ArrayList when I need a synchronized block that spas several different consecutive uses of the Vector?
And
Can ArrayList do the same effect as Vector in above aspect?
thanks for your time to answer
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"Of course it's thread-safe - Vector is snchronized!"


In case it wasn't clear - this was sarcasm. Some people believe that because they use a Vector, they're being thread-safe. Frequently, they're wrong.
In the security aspect,Is Vector better than ArrayList when I need a synchronized block that spas several different consecutive uses of the Vector?
No. Neither one is sufficient here - thread safety really comes from the synchronized block surrounding the code. It doesn't really matter that much whether you use Vector or ArrayList, as long as you use the synchronized block too. But ArrayList is going to be slightly faster here (in most cases), and doesn't confuse people by offering a false sense of "thread-safety".
Can ArrayList do the same effect as Vector in above aspect?
Yes. Aside from the case I just discussed, there are some times when you don't need synchronization across more than one method - you just need one method synchronized at a time. In these cases, you can get a synchronized version of ArrayList thus:
List syncList = Collections.synchronizedList(new ArrayList());
This syncList is very, very similar to Vector in the way it's synchonized. If you're sure this type of method-atomic synchronization is sufficient, then go ahead and use it. Since this is Performance, I will admit that Vector is probably slightly faster here. At least, it was around the time of 1.2, dunno if it still is. But I still feel that the benefit of Vector is small enough, and rare enough, that the class should be avoided as much as possible, for the other reasons cited. So OK, you may on rare occasions have a good use for Vector. But it should never be the first thing you try, IMO.
thanks for your time to answer
You're welcome.
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim
I am sure this type of method-atomic synchronization is sufficient.
And I must avoid to use Vector and use ArrayList substitute the Vector.
thanks for advancing my knowledge
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic