How can I execute bunch of different method or Runnable using "ExecutorService" parrally? I think you understood what I am trying to say.. Thanks
Asked
Active
Viewed 652 times
0
-
1Just go ahead and run them. – St.Antario Jan 27 '18 at 14:53
-
Possible duplicate of [What are the advantages of using an ExecutorService?](https://stackoverflow.com/questions/3984076/what-are-the-advantages-of-using-an-executorservice) – GalAbra Jan 27 '18 at 15:42
1 Answers
0
An application that creates an instance of Thread must provide the code that will run in that thread. There are two ways to do this:
Provide a Runnable object. The Runnable interface defines a single method, run, meant to contain the code executed in the thread. The Runnable object is passed to the Thread constructor, as in the HelloRunnable example:
public class HelloRunnable implements Runnable {
public void run() {
System.out.println("Hello from a thread!");
}
public static void main(String args[]) {
(new Thread(new HelloRunnable())).start();
}
}
Subclass Thread. The Thread class itself implements Runnable, though its run method does nothing. An application can subclass Thread, providing its own implementation of run, as in the HelloThread example:
public class HelloThread extends Thread {
public void run() {
System.out.println("Hello from a thread!");
}
public static void main(String args[]) {
(new HelloThread()).start();
}
}
See java documentation here https://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html

Honza
- 197
- 1
- 6