Excuse me if the question sounds silly - I'm just starting to use Executor.
I have an existing Java application that uses threads this way - mostly autonomous threads are used -
private Thread spawnThread( ) { Thread t = new Thread() { String taskSnap = task.toString(); public void run() { try { println( task.run( null ) ); }catch( InterruptedException e ) { println( "ITC - " + taskSnap + " interrupted " ); } } }; return t; }
As you can see above, the function returns a new thread.
Now in the main () function of the program a new thread is created in this way -
taskThread = spawnThread(); taskThread.start();
What I want to do is create an executor service (with a fixed number of threads) →, and then cancel the creation of a new thread / task execution by a new thread to this executor.
Since I am very new to Executor, I want to know how to modify the above code so that instead of a new separate thread, a new thread is created in the thread pool. I do not see any command to create a thread (in the thread pool) -> pass the above task to this thread (and not to a separate thread, as indicated above).
Please let me know how to solve this problem.
java multithreading executorservice threadpool
Arvind
source share