introducing lambda (#2305)
* moving jmh into libraries module * refactoring jmh * Update pom.xml * manual algorightm * with BM result * fix for space issue * Fixed indentation * change as per suggestion * vavr either * adding unit test and othe rutilities * adding concurrent module * concurrent package description * concurrent package description * Update EitherUnitTest.java * introducing lambda expression
This commit is contained in:
parent
f58c41de4d
commit
1be49ebc7f
|
@ -1,6 +1,5 @@
|
|||
package com.baeldung.concurrent.Scheduledexecutorservice;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
@ -12,32 +11,21 @@ public class ScheduledExecutorServiceDemo {
|
|||
public void execute() {
|
||||
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
ScheduledFuture<?> scheduledFuture = executorService.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// task details
|
||||
}
|
||||
ScheduledFuture<?> scheduledFuture = executorService.schedule(() -> {
|
||||
// Task
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
|
||||
executorService.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// task details
|
||||
}
|
||||
executorService.scheduleAtFixedRate(() -> {
|
||||
// Task
|
||||
}, 1, 10, TimeUnit.SECONDS);
|
||||
|
||||
executorService.scheduleWithFixedDelay(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// task details
|
||||
}
|
||||
executorService.scheduleWithFixedDelay(() -> {
|
||||
// Task
|
||||
}, 1, 10, TimeUnit.SECONDS);
|
||||
|
||||
Future<String> future = executorService.schedule(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
return "Hello World";
|
||||
}
|
||||
Future<String> future = executorService.schedule(() -> {
|
||||
// Task
|
||||
return "Hellow world";
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
|
||||
executorService.shutdown();
|
||||
|
|
|
@ -5,11 +5,9 @@ import java.util.concurrent.CyclicBarrier;
|
|||
public class CyclicBarrierExample {
|
||||
|
||||
public void start() {
|
||||
CyclicBarrier cyclicBarrier = new CyclicBarrier(3, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("All previous tasks are completed");
|
||||
}
|
||||
CyclicBarrier cyclicBarrier = new CyclicBarrier(3, () -> {
|
||||
// Task
|
||||
System.out.println("All previous tasks are completed");
|
||||
});
|
||||
|
||||
Thread t1 = new Thread(new Task(cyclicBarrier), "T1");
|
||||
|
|
|
@ -6,11 +6,8 @@ public class ExecutorDemo {
|
|||
|
||||
public void execute() {
|
||||
Executor executor = new Invoker();
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// task to be performed
|
||||
}
|
||||
executor.execute(()->{
|
||||
// task to be performed
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -10,15 +10,10 @@ public class ExecutorServiceDemo {
|
|||
|
||||
public void execute() {
|
||||
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// task details
|
||||
}
|
||||
executor.submit(() -> {
|
||||
new Task();
|
||||
});
|
||||
|
||||
executor.submit(new Task());
|
||||
|
||||
executor.shutdown();
|
||||
executor.shutdownNow();
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.baeldung.concurrent.future;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
@ -16,12 +15,10 @@ public class FutureDemo {
|
|||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
|
||||
Future<String> future = executorService.submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
Thread.sleep(10000l);
|
||||
return "Hello World";
|
||||
}
|
||||
Future<String> future = executorService.submit(() -> {
|
||||
// Task
|
||||
Thread.sleep(10000l);
|
||||
return "Hellow world";
|
||||
});
|
||||
|
||||
future.cancel(false);
|
||||
|
|
Loading…
Reference in New Issue