Skip to content

Instantly share code, notes, and snippets.

@czxttkl
Created October 18, 2013 02:03
Show Gist options
  • Save czxttkl/7035379 to your computer and use it in GitHub Desktop.
Save czxttkl/7035379 to your computer and use it in GitHub Desktop.
public class TryJoin {
public static void main(String... arg) throws InterruptedException {
Thread a = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Thread b = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
long start = System.currentTimeMillis();
a.start();
b.start();
a.join();
b.join();
long end = System.currentTimeMillis();
System.out.println("time:" + (end-start));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment