Created
October 18, 2013 02:03
-
-
Save czxttkl/7035379 to your computer and use it in GitHub Desktop.
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
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