Searching...
Saturday, 28 November 2015

Java 8 Executing Runnable using Lambda expression

12:54

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

 

 

 

0 comments: