Original Post
Hey guys! I thought I could do a nifty invoke function for a thread, which could be used by other threads to invoke functions as they were owned by that thread: But whenever I try calling this function in a situation like this: 1. Tread1 calls the function on Thread2 2. The task is pushed into Thread2's task pool and Thread1 waits for completion 3. Thread2 executes all the tasks given by other threads 4. Thread2 executes the task given by Thread1 now I would expect everything to go fine, but I get an exception: "Current thread not owner" on the "syncObj.notify()" but that's why I made the syncObj "final" right?? Anyone had a similar problem?
//This is a sync object just to make the current thread
//wait until the task has been completed by the targeted
//thread
final Object syncObj = new Object();
synchronized (syncObj) {
//make a task to be performed later on by the targeted
//thread
Runnable closeChannelTask = new Runnable() {
public void run()
{
/*try {
channel.close();
} catch( IOException e) {}*/
syncObj.notify();
}
};
//This will add the task to a list, and when the targeted
//thread runs again... this task will be performed
this.invoke(closeChannelTask);
try {
syncObj.wait();
} catch (InterruptedException e) {}
}
//Task was executed