Created
March 9, 2020 09:19
-
-
Save afrieirham/7eca41b60d805bd208dd99229c605621 to your computer and use it in GitHub Desktop.
Concurrent Programming Lab 1
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
package conprog_lab_1; | |
public class ConProg_Lab_1 { | |
public static void main(String[] args) { | |
PrintChar pc1 = new PrintChar('A', 10); | |
PrintChar pc2 = new PrintChar('B', 10); | |
PrintNum pn = new PrintNum(10); | |
Thread t1 = new Thread(pc1); | |
Thread t2 = new Thread(pc2); | |
Thread t3 = new Thread(pn); | |
t1.start(); | |
t2.start(); | |
t3.start(); | |
} | |
} | |
class PrintChar implements Runnable{ | |
private int times; | |
private char A; | |
public PrintChar(char A, int times) { | |
this.times = times; | |
this.A = A; | |
} | |
@Override | |
public void run() { | |
for(int i=0; i<this.times; i++) { | |
System.out.println(this.A); | |
try { | |
Thread.sleep(500); | |
} catch (InterruptedException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} | |
} | |
class PrintNum implements Runnable{ | |
private int times; | |
public PrintNum(int times) { | |
this.times = times; | |
} | |
@Override | |
public void run() { | |
for(int i=1; i<=this.times; i++) { | |
System.out.println(this.times); | |
try { | |
Thread.sleep(500); | |
} catch (InterruptedException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment