wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes executor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "executor" Watch "executor" New topic
Author

executor

meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305


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?


My one regret in life is that I am not someone else.
- Woody Allen
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: 305

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: 1753
    
    7

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: 305

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: executor
 
Similar Threads
synchronized
Deadlock / Object Lock ???
Thread synchronize question from JQ+ test
Synchronization
Basic thread doubt