Pi4J / pi4j-v1

DEPRECATED Java I/O library for Raspberry Pi (GPIO, I2C, SPI, UART)

Home Page:http://www.pi4j.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shared ScheduledExecutorService

savageautomate opened this issue · comments

Add ability to pass external executor service
(for example: it can be done by passing ScheduledExecutorServiceFactory to GpioFactory).

There also should me method like GpioController.getScheduledExecutorService if someone would use already created thread pool.

Some minor thougts:

  • when external ScheduledExecutorService was passed - Pi4J should not shutdown it on it's own shutdown (because this resource is managed by somebody, somewhere else).
  • when Pi4J internal ScheduledExecutorService is provided to external world (for example by GpioController.getScheduledExecutorService) is should not allow to be shuted down by anybody else than Pi4J (this can be done by returning ScheduledExecutorService inside wrapper - ScheduledExecutorServiceWrapper - where shutdown() and shutdownNow() throws UnsupportedOperationException)

Good suggestions and I agree with your points. Need to do some refactoring to address these.

Added support for this feature in the latest 0.0.5-SNAPSHOT (2013-02-09) build.

There is a new ExecutorServiceFactory implementation that allow users to provide their own executor service factory where you users can create the executors and manage own thread pool. Users can assign their own ExecutorServiceFactory implementation via the GpioController.

See https://github.com/Pi4J/pi4j/tree/develop/pi4j-core/src/main/java/com/pi4j/concurrent for more details.