Posted By:
Almagest_FUTT
Posted On:
Monday, August 8, 2005 02:01 PM
Pack your data retrieval process into a class implementing
Runnable and supporting the following features:
- Pass an Object (i'd suggest in the constructor) as a lock
- call notify on the lock when the computation has finished (don't forget to synchronize on it before)
- A method to query whether the computation has terminated
- A method to get the data loaded
Then, there where you process your request, you create:
- an Object to use as the lock
- one instance of the class described above using the Object you just created.
- an instance of Thread using the processing instance you just created (which in its turn implements Runnable)
Then write something like the following:
try{
synchronized (lock){
processthread.start();
lock.wait( WAITTIME );
//now, either you've been notified using notify(),
//which means the process has finished
//or the timeout expired
//check it
if( process.hasFinished() ){
//get the data from the processor and send it
} else {
//notify the processor in some way that
//when he'll be finished, he'll have to store
//his results in some way
}
}
}
catch(InterruptedException xx){
// ??
}