Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- t t1 = new t(1);
- t t2 = new t(2);
- t1.start();
- t2.start();
- try {
- t1.join(5000);
- System.out.println(t1.isAlive());
- t2.join(5000);
- System.out.println(t2.isAlive());
- }
- catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
- class t extends Thread {
- int id;
- public t(int _id) {
- id = _id;
- }
- @Override
- public void run() {
- for(int i = 0; i < 10; i++) {
- System.out.println("Thread " + id + " " + i);
- try {
- Thread.sleep(100);
- }
- catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement