Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to lock my Method  RSS feed

 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ranchers

I have a scenario where when a call to particular method is being invoked it shouldn't be able to be invoked by other instances.Take a look into the following code.






my question is the logic method which has been synchronized should not be able to be invoked untill the first invocation finishes it's execution then realized that it's completely a different object so it forms a different entries on the heap which will reffered by x & y.
But i want the invocation of y to be restricted when x is using the logic method, what are the changes to be undergo.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the same instance, use a synchronized static method or use a static lock. That should work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!