• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question to Peter Haggar

 
L Goundalkar
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is regarding the Praxis 34 "Minimize Synchronization" in the book "Practical Java".
To eliminate unnecessary synchronization you have given two options. One of them is :
" Use alternative class that provides unsyncronized methods."
You have mentioned to use Vector or ArrayList, ArrayList is insisted. But this option is selected to minimize the memory overhead which is in case of providing a subclass with unsynchronized version of the method.
But in the Vector/ArrayList option also, we are creating different objects of the class. Doesn't this consume memory ?
Can you please explain these options in detail.
Thanks for the time.

------------------
L Goundalkar
lggoundalkar@hotmail.com
Sun Certified Programmer for Java 2 Platform
 
Peter Haggar
author
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not advocating using both a Vector and ArrayList. All I'm saying is in cases where you don't need synchronization, you should use an ArrayList instead of a Vector. The ArrayList is unsynchronized, while the Vector is synchronized.
Even in single threaded applications, without thread contention, the Vector is quite a bit slower than the ArrayList. In addition, you can quite easily replace usage of a Vector with an ArrayList since they both support the same interface.
Peter Haggar
------------------
Senior Software Engineer, IBM
author of: Practical Java
 
L Goundalkar
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,
I think i didn't convey my doubt properly.
Since we are dealing with memory consumption problem ( which inturn will slow down the process ) here, then how can the use of number of objects in either Vector / ArrayList will solve the problem of Slow Processing ?
Thanks.

------------------
L Goundalkar
lggoundalkar@hotmail.com
Sun Certified Programmer for Java 2 Platform
 
Peter Haggar
author
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not talking about memory consumption, nor is my book. Praxis 34 is about execution speed differences with and without synchronization regarding Vector and ArrayList. If you are asking about memory consumption between these two classes, as far as I know, there is no difference. Both should use about the same amount of memory as the other, given the same set of elements to hold.
Peter Haggar
------------------
Senior Software Engineer, IBM
author of: Practical Java
 
L Goundalkar
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. I got It.
Thanks a lot.

------------------
L Goundalkar
lggoundalkar@hotmail.com
Sun Certified Programmer for Java 2 Platform
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!