Java 8 Executing Runnable using Lambda expression

In java 8 it is very easy to execute a runnable using Lambda.. see how it works package com.vinod.test;

package com.vinod.test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Java8RunnableExample {
private static ExecutorService executor = null;
public static void main(String[] args) {
Runnable r = () -> print();
executor = Executors.newFixedThreadPool(2);
executor.submit(r);
}

private static void print() {
System.out.println("Vinod");

}
}

Output

Vinod

 

 

 

No comments:

Post a Comment

12 classic String-based Java interview questions with simple explanations and code.

  1️⃣ Check if a String is a Palindrome Problem Given a string, check if it reads the same forward and backward. Example: "madam...

Featured Posts