I have a Java program that is using pi4j project to interact with the GPIOs. I have one test class that listens for a button to be pressed and then does something. The class is part of many in a larger program and it is possible that it is created and run multiple times, and this is causing the problem.
On the first execution I have no problem and everything runs and works as expected, but when executing a second (or more) times then I'm getting an "RejectedExecutionException" error when the button is pressed.
Full stack trace
Exception in thread "Thread-14" java.util.concurrent.RejectedExecutionException: Task com.pi4j.io.gpio.tasks.impl.GpioEventDispatchTaskImpl@11f409d rejected from java.util.concurrent.ThreadPoolExecutor@1d8bcce[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 12]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1369)
at com.pi4j.concurrent.ShutdownDisabledExecutorWrapper.execute(ShutdownDisabledExecutorWrapper.java:113)
at com.pi4j.io.gpio.impl.GpioEventMonitorExecutorImpl.handlePinEvent(GpioEventMonitorExecutorImpl.java:91)
at com.pi4j.io.gpio.GpioProviderBase.dispatchPinDigitalStateChangeEvent(GpioProviderBase.java:332)
at com.pi4j.io.gpio.RaspiGpioProvider.pinStateChange(RaspiGpioProvider.java:206)
at com.pi4j.wiringpi.GpioInterrupt.pinStateChangeCallback(GpioInterrupt.java:126)
Now to me it seems like something is not being shutdown properly, but I can't find what it is!
My code is as follows;
Constructor
GpioPinDigitalInput buttonPin;
this.buttonPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_03, PinPullResistance.PULL_DOWN);
this.buttonPin.setShutdownOptions(true, PinState.LOW);
this.buttonPin.addListener(this);
Shutdown
this.buttonPin.removeAllListeners();
gpio.unprovisionPin(buttonPin);
this.gpio.shutdown();
I would appreciate some help to track down what the problem is.
Thanks