Last active
December 11, 2015 05:58
-
-
Save tomgullo/4555817 to your computer and use it in GitHub Desktop.
simple test using threads
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
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