• Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronized method or block vs vector

 
ajay verma
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22532
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
amitt jainn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!