One of the things a core java server i’m running does is process two type of tasks (T1 and T2) . Originally these tasks were being processed from the same queue and thread. At times the queue contains about 1000 T1 tasks which cause delays for the next T2 task. So i decided to change the architecture and process each task in a separate thread and separate queue. But it looks like the JVM will still process the ~1000 T1 tasks (about .6 seconds) before switching to the other thread and processing T2 tasks.
I’m running on a quad core machine running “Red Hat Enterprise Linux Server release 6.1 (Santiago)”.
I’m assuming that the two threads are being run on the same CPU.
Is there any way to facilitate the OS or JVM to switch more often?
Also is there a way to see which thread is being processed by which processor?
I’ve verified that both threads are running as separate threads using a debugger.
One thread is created using
this.executor.Executors.newSingleThreadExecutor();
And tasks are submitted using
executor.submit(new Task2(..));
The other thread is legacy code that manages it’s own queue:
private final BlockingQueue<...> workQueue = new LinkedBlockingQueue<...>();
....
public void submit(Task1 task) {
workQueue.add(task);
}
....
public void run() {
while (alive){
try{
Task1 task = workQueue.take();
processwork(task);
}
....
After more analysis I found the delay was caused earlier (before submitting) by another thread that the two tasks share.