Last active
December 12, 2015 08:29
-
-
Save pankajmi/4744483 to your computer and use it in GitHub Desktop.
Use of DynamicVariable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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