I've one ThreadPoolExecuter
to run multiple thread at the same time. in Runnable
, I want to run method in another thread so, I've create another thread (thread A) in execute method, now I want to get result of thread A to run in executor thread.
let me clarify with one sample:
ThreadPoolExecuter threadPool = Executors.newFixedThreadPool(5);
threadPool.execute(new Runnable() {
@Override
public void run() {
// do something in threadPool thread
// call method in thread A
getInfo(new QueryExecutorInterface() {
@Override
public void onPostExecute(Cursor cursor) {
// do other thing in threadPool thread again.
}
});
}
});
QueryExecutorInterface
is my interface that I've want to pass to thread A
and get result on ThreadPool
thread. as I've call listener call back like following method i get result in thread A
:
class A extend Thread {
@Override
public void run() {
// do something in thread A.
queryExecutorInterface.onPostExecute(cursor);
}
}
PS: I can fix this scenario with using ReentrantLock
class instead of using Thread A
. but as I have one another layer above this I don't want to use locking.