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

synchronization without Threads  RSS feed

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to synschronize a method so that whether it gets called by a Thread or an ordinary method, it will wait until the first one is finished with it?
I've just tried this by sticking the synchronize keyword on a method but it seemed to make no difference.
If it is possible, do I need to do more than just use the synchronize keyword?
Thanks.
Paul
 
Vin Kris
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a case of a single resource shared by multiple threads - typically in a web application where a singelton object is used to maintain some global information. Then the methods in this class would be synchronized so that the data maintained is consistent.
Otherwise, you have already discovered the rest. Synchronizing on normal methods wouldn't make any difference to the program - but i suppose the monitor would anyway be obtained. I'll have to check up on this.
 
Vin Kris
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

trial-1)
Sync - 39066.0
Norm - 8883.0
trial-2)
Sync - 40658.0
Norm - 9003.0
The synchronizing on a normal method is just a waste of resource.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is moot.
Synchronization is meaningless without resources in which to synchronize [between.]
Methods are only called by methods. Threads do not call anything.
[ October 10, 2002: Message edited by: CL Gilbert ]
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all responses....
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you though, comprehend the responses?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!