• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can a Vector be synchronized AGAIN????

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have seen the folowing code in this forum:

Since Vector is already synchronized, is synchronized (Vector) necessary ? What does it mean by synchronizing (synchronizing something)
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My suggestion is to use a HashSet instead, it works just like a Vector, and it is faster, one of the newer Collection objects, and cleaner than Vectors.
I would avoid Vectors and HashTables as they are from older versions of Java and the Newer Collections classes are newer. I actually had started using Vectors and Hashtables, since I knew them so well, but I changed them to the new Collections, and it actually reduced a bunch of my code.

Mark
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, to answer your question about synchronization you might look at the postings under Threads and Synchronization.
Second, it looks like the author of the above code is trying to prevent any other threads from accessing the vector until this thread done with his while loop. Though the Vector is synchronized and only be accessed by one thread at a time, in this case if it was not in a sync block another thread could manipulate the vector (add, remove, removeall, etc) any where in the while loop.
Third, I would take Mr. Mark Spritzler's advice in the earlier posting and not use Vectors.
Good luck, threading/synching can be tricky to understand and debug.
Aaron
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic