Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Using an executor

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've created my own PooledExecutor to create and manage a variable size thread pool. I've become a bit unstuck as to how to actually "initiate" the executor so to speak so that it begins to create threads and assign tasks to them.

Thanks
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Deyna Cegielski:
I've created my own PooledExecutor to create and manage a variable size thread pool. I've become a bit unstuck as to how to actually "initiate" the executor so to speak so that it begins to create threads and assign tasks to them.

Thanks



Hi Deyna,
If you are using java 5 then different types of executors are available. You do not need to write one.
If not, then sharing the code, will probably help in understanding where you are stuck.
 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, in that light, lets forget about how ive implemented the executor, using one of the executors in Java 5, how would i initialise it to start managing the threads and tasks?
 
author
Posts: 23912
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Deyna Cegielski:
Thanks, in that light, lets forget about how ive implemented the executor, using one of the executors in Java 5, how would i initialise it to start managing the threads and tasks?



The easiest place to start is with the convenience factory for executors. One of the factory methods should provide you with a executor that would work. If that is not the case, you can click on the Javadoc from that page, to configure an executor to your specifications.

Henry
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Creating an instance of the executor initialize it and submitting a task via execute method executes the task.
Pls. refer to api for api details.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a real life example to show how darned simple it is to use such complex goodies. This is a web server ...

This particular executor creates new threads without bounds and terminates them if they're idle for a minute.
 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, that was what i was after, a pool of x threads continuously running and services requests until the requests stop!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic