Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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.
 
Climb the rope! CLIMB THE ROPE! You too tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic