Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

DeadLock with ThreadPoolExecutor  RSS feed

 
Steven Rodeo
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are consistently hitting Deadlock with implementation of ThreadPoolExecutor

We are creating a ThreadPool using the newCachedThreadPool()

myThreadPool = Executors.newCachedThreadPool();

// Execute this folder in a seperate thread.
myThreadPool.execute(
new MyRunnable(buddy,nice)
);

The problem we're currently running in to is that when one of the threads, in the threadpool is stuck... the other threads are stuck . And this is what we see with the jstack.

Is there any way we can do some thing about this

1) some thing kill this looping thread ?
2) Any other option?

 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven:
We are consistently hitting Deadlock


Why do you say that there is a deadlock? Do you see 2 threads like the following:

Thread 1: Holds lock on Object A, Waiting for lock on Object B
Thread 2: Holds lock on Object B, Waiting for lock on Object A

You can get a list of locks held by current threads in jstack using "-l" option.
In fact, jstack will tell you if there is a deadlock. So, if jstack output does not say that there is a deadlock then there is none.

(The above is for java 6, i am not sure about earlier versions. For earlier versions, You can either google or write a small test program that creates deadlock and check jstack on that.
I think prior to jdk 6, jstack did not use to give locks taken using java concurrent library)

Steven:The problem we're currently running in to is that when one of the threads, in the threadpool is stuck... the other threads are stuck . And this is what we see with the jstack.

I am not clear as to what you are referring to as "stuck", do you mean it is waiting for an I/O or monitor or simply running in an infinite loop?
Your Jstack output only shows threads in BLOCKED state that means they are waiting to take a lock(either entering a sync block or coming out of wait())
Inside your task, do you try to acquire locks or wait for jobs from queues?

Steven:
Is there any way we can do some thing about this
1) some thing kill this looping thread ?


If the task responds to interrupt then you can call cancel() on the Future obtained on submitting the task.

Steven:
Any other option?


Not really, if the task does not respond to interrupt.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!