| Author |
executor
|
meeta gaur
Ranch Hand
Joined: Dec 05, 2012
Posts: 225
|
|
pool-1-thread-2
pool-1-thread-1
why doesn't program stop ? why does it hang after above output?
and another thing, i invoked execute method two times, does it mean it will start two new threads using only one executor object?
|
OCAJP
|
 |
Emanuel Kadziela
Ranch Hand
Joined: Mar 24, 2005
Posts: 186
|
|
The program doesn't stop because the Executor is still running. Try e.shutdownNow() at the end of your code snippet.
When you called Executors.newFixedThreadPool(3) you created an executor with 3 threads (read the javadocs). When you call execute() it uses one of those 3 threads to execute the runnable.
|
 |
meeta gaur
Ranch Hand
Joined: Dec 05, 2012
Posts: 225
|
|
Emanuel Kadziela wrote:The program doesn't stop because the Executor is still running. Try e.shutdownNow() at the end of your code snippet.
When you called Executors.newFixedThreadPool(3) you created an executor with 3 threads (read the javadocs). When you call execute() it uses one of those 3 threads to execute the runnable.
Thanks.I am using Executor interface not ExecutorSerive interface.It hasn't any shutdown method.
ExecutorExample1.java:17: error: cannot find symbol
e.shutdownNow();
^
symbol: method shutdownNow()
location: variable e of type Executor
1 error
|
 |
Jelle Klap
Bartender
Joined: Mar 10, 2008
Posts: 1405
|
|
|
Then you should probably switch to the ExecutorService interface.
|
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
|
 |
Emanuel Kadziela
Ranch Hand
Joined: Mar 24, 2005
Posts: 186
|
|
Please read the javadocs
And just change this:
to this:
|
 |
meeta gaur
Ranch Hand
Joined: Dec 05, 2012
Posts: 225
|
|
Yes i will use that.Seems Executor is useless, a car without break.
|
 |
sajid toor
Greenhorn
Joined: Nov 25, 2012
Posts: 1
|
|
|
now i know,thanks for sharing.
|
http://www.cslawtalk.com
|
 |
 |
|
|
subject: executor
|
|
|