• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread synch

 
Ruslan Ivanov
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i have this sample in myboo where they have a synch method defined as follows
public syncrhonized void send(Object obj){
que.addElement(obj);
}
now que is a vector why would i want to make send method synch if all the methods in vector are already synch this doesn't make sence to me. What does this accomplish ? I understand if i had something more going on in this method like changing state of a variable that has someting to do with my object then yes it would make sence to make it synch so other threads can't access this method until the first one in won't unlock it. Otherwise what's the point of this ?Thanks.
 
Rahul Rathore
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this discussion http://www.javaranch.com/ubb/Forum27/HTML/000259.html
 
Mark Savory
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ruslan,

The object that contains the method 'send' must be locked before calling 'send'. Maybe there's another method in that object that must be synchronized with 'send' for whatever reason.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!