move demo documents into separate files
This commit is contained in:
parent
8ee1ffab20
commit
426259dc2f
23 changed files with 466 additions and 495 deletions
26
demo/docs/groovy.groovy
Normal file
26
demo/docs/groovy.groovy
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
//http://groovy.codehaus.org/Concurrency+with+Groovy
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
def counter = new AtomicInteger()
|
||||
|
||||
synchronized out(message) {
|
||||
println(message)
|
||||
}
|
||||
|
||||
def th = Thread.start {
|
||||
for( i in 1..8 ) {
|
||||
sleep 30
|
||||
out "thread loop $i"
|
||||
counter.incrementAndGet()
|
||||
}
|
||||
}
|
||||
|
||||
for( j in 1..4 ) {
|
||||
sleep 50
|
||||
out "main loop $j"
|
||||
counter.incrementAndGet()
|
||||
}
|
||||
|
||||
th.join()
|
||||
|
||||
assert counter.get() == 12
|
||||
Loading…
Add table
Add a link
Reference in a new issue