ExecutorService slow and hung sometime ExecutorService slow and hung sometime kubernetes kubernetes

ExecutorService slow and hung sometime


and i observed ExecutorService very slow to response.

ExecutorService WORKER_THREAD_POOL = Executors.newFixedThreadPool(100);

Let's start with the question: How many cores does your machine have?
For, newFixedThreadPool, it is suggested to start with as many threads as the number of cores in your machine (if the tasks are long running ones). With a value of 100, your CPU is going to be busy with scheduling and context-switching. On top of that, since it's a newFixedThreadPool, so many threads are going to remain in pool even when there is less load - not helpin the CPU.

As suggested in Effective Java, newCachedThreadPool usually does the good thing.Here is more on the Thread Pools.

If you are expecting a really heavy load, I think deployment of apps on multiple servers would be the wise thing to do (this depends on the capacity of your single server). Threads are not going to help and can eventually make your app slow.


When you deploy an application in kubernetes if you do not specify the memory and cpu requirement then kubernetes scheduler schedules the pod into a node on best effort basis which can lead to starvation and even eviction of the pod.

You can help the scheduler to take a better scheduling decision by specifying the memory and cpu requirements as below

apiVersion: v1kind: Podmetadata:  name: frontendspec:  containers:  - name: app    image: images.my-company.example/app:v4    env:    resources:      requests:        memory: "64Mi"        cpu: "250m"      limits:        memory: "128Mi"        cpu: "500m" 

This will make sure the pod gets scheduled on a node which can satisfy requirement of starting with 64Mi memory,250m cpu and allow it to burst upto 128Mi memory, 500m cpu.