Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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.
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!