I have a problem with my java service , The problem arises when our database cpu utilization goes up. Now I wonder why wouldn't my java-service return to normal after the database(mysql) has recovered. Im using database pooling using bonecp 0.7.1 RELEASE
This is my CachedThreadPool i used:
final int MAX_CORES = Runtime.getRuntime().availableProcessors();
protected ExecutorService threadPool = new ThreadPoolExecutor(MAX_CORES,MAX_CORES ,
60L, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
new DiscardPolicy());
I have a discard policy that when something happened like the threadpool wont accommodate new task. Ill put it in my pending concurrent hashmap for later work.
public class DiscardPolicy extends ThreadPoolExecutor.DiscardPolicy{
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
// TODO Auto-generated method stub
super.rejectedExecution(r, e);
Constants.pendingRunnables.put(e, r);
}
}
And this is my MqttServer to acquire task
@Override
public void messageArrived(final String topic, final MqttMessage message) throws Exception {
try{
if(Constants.pendingRunnables.size() > 0){
for(java.util.Map.Entry<ThreadPoolExecutor, Runnable> runner : Constants.pendingRunnables.entrySet()){
Constants.pendingRunnables.remove(runner.getKey());
runner.getKey().execute(runner.getValue());
}
}
}catch(Exception e){
}
threadPool.execute(new Runnable(){
// any kind of task to run depending on what topic
});
}
Is there something I'm missing here?