• 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

Vectors

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have written an application that reads data from a database, displays the data on a JTable that can be modified with edits, insertions and deletions that thereafter update, insert or delete database tables. I am using vector as the underlaying data structure. I have read somewhere that vectos are thread safe, meaning, correct me if I am wrong, that a vector's additions or removal operatons coming from one thread are blocked until another thread completes its additions or removal operations. I am not using threads; this is a single threaded application; but since this application is going to be distributed to several users, and there will be several database connection requests, I have included a serializable isolation statement and implemented transactions so that no dirty reads, phatom reads and no-repetable reads may occur. My question is; since several users are going to be using the application and therefore the application vectors are going to be read and modified by several users at the same time; should the fact that vectors are synchronyzed take care of any problems or is there any thing else I should do to make sure that a vector is not modified in any way until one user's process has completed?

Thank you,

Giuseppa
 
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vectors give you nothing in this case, they don't work cross process, you have multiple threads just not in the same process and they only communicate via the database.

Presumably its all down to how you have implemented transactions.

Normally you lock the data in the database to prevent concurrent writes such that one user must complete first or allow a subsequent transaction commit to fail based on change having happened (optimistic) and rollback the dirty write.
 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your response. I do not anserstand very well this part "Vectors give you nothing in this case, they don't work cross process, you have multiple threads just not in the same process and they only communicate via the database." Does this mean that since this is not a multithreaded application, vectors do not take care of synchronization because there is nothing to synchronize and that since the threads are issued by the database, the concurrency control depends in the transactions impementation?

 
Chris Hurst
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vectors would synchronize two threads in the same process only, as your threads are in separate processes / applications they can't communicate with each other and have their own instance of the vector. In a single threaded application the synchronization of vector is not useful (does nothing).
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The other problem with your original post: whatever you read which said that Vector is "thread safe" was incorrect. It isn't. Sure, all of its methods are synchronized, but that isn't enough to provide full thread safety.

However as Chris says, it's irrelevant in your situation anyway.
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about LinkedList instead of Vector?
 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all very much for your responses. As for " How about CopyOnWriterArrayLists instead of Vectors? " What would be the purpose of this in a singlethreaded application?
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic