Programs On16th Nov
Programs On16th Nov
}
public class TestThread1 {
System.out.println(Thread.currentThread().getName
());
}
}
}
THREAD4.
class UserThread4 extends Thread{
public void run(){
System.out.println("Thread
name:"+Thread.currentThread().getName()
+"priority:"+Thread.currentThread().getPriority()
);
}
}
public class TestThread4 {
t1.setPriority(Thread.NORM_PRIORITY);
t2.setPriority(Thread.MAX_PRIORITY);
t3.setPriority(Thread.MIN_PRIORITY);
t4.setPriority(Thread.NORM_PRIORITY);
t1.start();
t2.start();
t3.start();
t4.start();
}
THREAD5:
class UserThread5 extends Thread{
public void run(){
if(Thread.currentThread().isDaemon())
System.out.println("Daemon thead is
running");
else
System.out.println("Userthread is
running");
}
}
public class TestThread5 {
obj1.setDaemon(true);
obj1.start();
obj2.start();
}
THREADPOOL PROGRAM
import java.util.concurrent.ExecutorService;//interface
import java.util.concurrent.Executors;//class
class WorkerThread implements Runnable{
private String msg;
public WorkerThread(String msg){
this.msg=msg;
}
@Override
public void run() {
System.out.println(Thread.currentThread().getName()+"(
start)message="+msg);
processMsg();
System.out.println(Thread.currentThread().getNam
e()+"(end)");
}
private void processMsg(){
try{
Thread.sleep(1400);
}catch(Exception e){
System.out.println(e);
}
}
}
public class TestThreadPool {
}
executor.shutdown();
while(!executor.isTerminated()){}
System.out.println("finished all
thread...............");
}
}
ExWithoutLambda:
interface Myinterface{
void show();
}
public class ExWithoutLambda {
ExLambdaWithParameter:
interface Printable{
public String someprint(String name);
}
public class ExLambdaWithParameter {
};
System.out.println(p1.someprint("krishna"));
ExLambdawithParameter2:
import java.util.*;
interface Oddeven{
String check(int num1);
}
public class ExLambdawithParameter2 {
};
System.out.println(obj.check(num));
}
ExLambda3:
@Override
public void run() {
System.out.println("thread is
running...");
};
Thread t1=new Thread(r1);
t1.start();
Runnable r2=()->{
System.out.println("thread2 is
running...");
};
Thread t2=new Thread(r2);
t2.start();
}