I need a Java 8 example of multi-threading.
I need to be able to manually select the number of threads.
In the example below I have a problem with Thread.currentThread().getName(), and I need to use a lambda expression.
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Thread {
public static void main(String args[]) {
ExecutorService service = Executors.newFixedThreadPool(10);
for (int i =0; i<100; i++){
service.submit(new Task(i));
}
}
final class Task implements Runnable{
private int taskId;
public Task(int id){
this.taskId = id;
}
@Override
public void run() {
System.out.println("Task ID : " + this.taskId +" performed by "
+ Thread.currentThread().getName());
}
}
Thread.currentThread().getName()?java.lang.Thread.currentThread().getName()