executors java
ExecutorService executor = Executors.newFixedThreadPool(10);
executors java
ExecutorService executor = Executors.newFixedThreadPool(10);
newSingleThreadExecutor
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class TestThread {
public static void main(final String[] arguments) throws InterruptedException {
ExecutorService executor = Executors.newSingleThreadExecutor();
// very simple example, check the website for more info:
// https://www.tutorialspoint.com/java_concurrency/concurrency_newsinglethreadexecutor.htm
executor.submit(new Task());
System.out.println("Shutdown executor");
executor.shutdown();
}
}
static class Task implements Runnable {
public void run() {
try {
Long duration = (long) (Math.random() * 20);
System.out.println("Running Task!");
TimeUnit.SECONDS.sleep(duration);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us