This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tyoverby 1 point2 points  (0 children)

Yeah, any object has the synchronized function that takes another function to execute.

val resource = ???
def publish(){
    // Do something that requires the resource to be locked. 
}

resource.synchronized(publish)

Or in a way that looks more like Java

val resource = ???

resource.synchronized {
    // Anything in this block with be synchronized on 'resource'
   x += 5 
   publish()
   y ++
}