• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Thread synch  RSS feed

 
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.
 
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
 
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.
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!