• 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
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!