aspose file tools
The moose likes Threads and Synchronization and the fly likes synchronized method or block vs  vector Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "synchronized method or block vs  vector" Watch "synchronized method or block vs  vector" New topic
Author

synchronized method or block vs vector

ajay verma
Ranch Hand

Joined: Dec 10, 2007
Posts: 37
if i apply the method level synchronization or block level synchronization with any of the legacy class objects like(vector,dictionary,properties,hashtable)!
will the thread will behave same as it is behaving with others,means(it will also treat as a normal class object)1

reply asap
thank you
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16692
    
  19

Most of the classes that you listed are already synchronized -- what do you have in mind? Do you want to synchronized it with another lock?


To answer your question, how those classes' behavior changes depends on what you change. Kinda obvious, if you change something, something will change -- maybe if you give us some context on what you are intending to do.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
amitt jainn
Greenhorn

Joined: Jan 21, 2008
Posts: 4
Ajay !

In your case when you have a synchronized method and within that you are using historic collection (which are impliclitly synchronized) then it will be the suitable senario for reentrant synchronization

Since a thread cannot acquire a lock owned by another thread. But a thread can acquire a lock that it already owns. Allowing a thread to acquire the same lock more than once enables reentrant synchronization. This describes a situation where synchronized code, directly or indirectly, invokes a method that also contains synchronized code, and both sets of code use the same lock.

Regards
AMIT JAIN
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: synchronized method or block vs vector
 
Similar Threads
Synchronization question
Regarding Threads!!
Synchronization
ArrayList vs Vector
Differences between the two types of Thread synchronization