Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Step 1: prepare the task as a runnable:
- final Runnable runnable = new Runnable() {
- @Override
- public void run() {
- // ...
- }
- };
- // Or as a Lambda (since Java 8):
- // final Runnable runnable = () -> { ... };
- // Step 2: Run it.
- final Thread t = new Thread(runnable);
- // optional: set name, priority etc.
- t.start();
- // **** OR: *****
- final ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
- pool.execute(runnable);
- // Tip: use pool.submit(Callable) to execute a non-void method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement