Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization and Performance  RSS feed

 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my java application i was making a lot of substring,indexOf and equalsIgnoreCase operations over the string objects.in order to avoid such operations i restructured my applications such that all this applications will be done only once and the resultting string objects will be kept in the cache(in a Vector) but now the dissapointing factor is that the my application is much slower than the previus one
When i compare the two versions of my application in the second version i am reading more often from two java.util.Properties,and java.util.Vector objects(But they are never get modified once loaded in my application)
Is these Synchronized objects like Properties and Vector reduces the performance of my application
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The properties should be no more than hashtables in disguise, so they are OK. The use of a Vector makes me wonder how you are finding your cached values in that Vector. If you're doing a linear search, then you've traded an O(1) algorithm for an O(n) one -- almost always a bad move. Try a sorted data structure and a binary search, or a map, in that case.
If you don't need synchronization, then the synchronization is just so much wasted CPU cycles, but I wonder if it should affect performance this badly.
- Peter
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ArrayList is a non-syscronized version of Vector, it is faster. If you know the size, use array instead is at least 3 times faster than a Vector.
If you need to search the array, then Binary search tree is much faster if the size is very big.
Roseanne
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!