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

object locking  RSS feed

 
rama rajesh
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i could not get the locking concept clearly. please somone explain me by taking this prg as example
until synchNonStat1 method completes , thread t1 can't enter into synchNonStat2 method. but in between these two,
1. is there any chance of calling nonsynchNonstat1 method?
2. is there any chance of invoking nonsynchNonstat2 method while executing the nonsynchNonstat1 method

 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to use the example you showed? It's not going to show anything about locking/synchronization because you're only using one thread. The java tutorials have a nice section about synchronization: here.
 
rama rajesh
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My knowledge on this.

A thread can't enter any of static synch methods of a class, if any other thread is executing the static synchro method of class(Locking on class will be happened)
if a thread entered the nonstatic synchr method of a object, any other thread can't enter the any of the nonstatic synch method of that object(object locking will be happened).

 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need the second thread creation (t2) back in for this example to be worth comment.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!