Skip to content

Instantly share code, notes, and snippets.

@pankajmi
Last active December 12, 2015 08:29
Show Gist options
  • Save pankajmi/4744483 to your computer and use it in GitHub Desktop.
Save pankajmi/4744483 to your computer and use it in GitHub Desktop.
Use of DynamicVariable
val dyn = new DynamicVariable[Int](0)
new Thread(new Runnable() {
def run() {
dyn.withValue(10) { doSomething }
}
}, "thread-1").start()
new Thread(new Runnable() {
def run() {
dyn.withValue(20) { doSomething }
}
}, "thread-2").start()
def doSomething() {
println {
Thread.currentThread().getName() +
" " + dyn.value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment