• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

executor

 
Ranch Hand
Posts: 305
Tomcat Server Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 305
Tomcat Server Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you should probably switch to the ExecutorService interface.
 
Emanuel Kadziela
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read the javadocs

And just change this:


to this:

 
meeta gaur
Ranch Hand
Posts: 305
Tomcat Server Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i will use that.Seems Executor is useless, a car without break.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now i know,thanks for sharing.
 
The only thing that kept the leeches off of me was this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!