Created
September 14, 2014 13:43
-
-
Save jtuttas/6ab4b8af1fc7e73d246a to your computer and use it in GitHub Desktop.
Threads Fork and Join
This file contains hidden or 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 Main { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Zaehler z1 = new Zaehler("Nummer 1", 3); | |
Zaehler z2 = new Zaehler("Nummer 2", 6); | |
z1.start(); | |
z2.start(); | |
while (z1.isAlive() && z2.isAlive()) { | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
System.out.println("Zählen beendet!"); | |
} | |
} |
This file contains hidden or 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 Zaehler extends Thread { | |
private int zahl; | |
public Zaehler (String n, int z) { | |
super(n); | |
zahl=z; | |
} | |
public void run() { | |
for (int i=0;i<zahl;i++) { | |
System.out.println ("Thread "+getName()+": ist bei "+i); | |
try { | |
this.sleep(100); | |
} | |
catch (InterruptedException ix) { | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment