Java Service Stops Running when Rejected Execution triggers
I have a running mqtt-client that acts as a bridge/server for Android apps and database pooling for MySQL and when rejected execution triggers my service stops, I'm really wondering why.
This is my threadpool
public static ExecutorService threadPool = new ThreadPoolExecutor(10, // core size
30, // max size
10*60, // idle timeout
TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(20),
factory,
new DiscardPolicy()); // queue with a size
Ad this is how my message arrived performs
@Override
public void messageArrived(final String topic, final MqttMessage message) throws Exception {
threadPool.execute(new Runnable(){
void run(){
if(topic.equalsIgnoreCase("something")){} // and code goes on like these
}
// code
});
try{
if(Constants.pendingRunnables.size() > 0){
for(java.util.Map.Entry<ThreadPoolExecutor, Runnable> runner : Constants.pendingRunnables.entrySet()){
// runner.getKey().execute(runner.getValue());
try{
if (!runner.getKey().isShutdown()) {
runner.getValue().run();
Constants.pendingRunnables.remove(runner.getKey());
}
}catch(Exception ex){
}
}
}
}catch(Exception e){}
}
public class DiscardPolicy extends ThreadPoolExecutor.DiscardPolicy{
private static final Logger LOGGER = Logger.getLogger(DiscardPolicy.class);
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
// TODO Auto-generated method stub
super.rejectedExecution(r, e);
Constants.pendingRunnables.put(e, r);
LOGGER.info("Rejected Runnable ");
}
}
Some runnables have mqtt client in them so that they could publish a response. What these service do is run runnables and when exception triggers I append them to pending runnables so that I could run them later.
Do I have something missing here?