Java Lab 8
Java Lab 8
}
}
class A11 implements Runnable {
String msg;
A11(String m){
msg=m;
}
public void run(){
for (int i = 0; i < 5; i++) {
System.out.println(msg);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
}
4. Using Lambda Expression
public class DemoLambda {
public static void main(String[] args) {
A111 A = new A111();
A.start();
Thread t=new Thread(()->{
for (int i = 0; i < 5; i++) {
System.out.println("Hai OMU Libya");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Advanced Programming Using Java - Prepared by: Krishna Kumari Ganga
e.printStackTrace();
}
}
}
);
t.start();
}
}
class A111 extends Thread {
public void run(){
for (int i = 0; i < 5; i++) {
System.out.println("Hai OMU");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
}
5. Example program on inter-thread communication using piped input stream class and
piped output stream class
import java.io.*;
import java.util.*;
public class PipeTest {
Best of luck