Skip to content

Instantly share code, notes, and snippets.

@tomgullo
Last active December 11, 2015 05:58
Show Gist options
  • Save tomgullo/4555817 to your computer and use it in GitHub Desktop.
Save tomgullo/4555817 to your computer and use it in GitHub Desktop.
simple test using threads
import java.util.concurrent.CountDownLatch
class MyRunnable implements Runnable {
def myParam, latch
public MyRunnable(String myParam, CountDownLatch latch){
this.myParam = myParam;
this.latch = latch
}
public void run(){
try {
Thread.sleep(1000)
} finally {
latch.countDown()
}
}
}
def num_threads = 3
final CountDownLatch latch = new CountDownLatch(num_threads)
def s = System.currentTimeMillis()
for (int i = 0; i < num_threads; ++ i)
{
( new Thread( new MyRunnable("test" + i, latch) ) ).start()
}
latch.await();
println ( System.currentTimeMillis() - s )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment