Pausing a multi-threaded download
Hi,
I'm working on a multi-threaded download manager. The code given below is run by several threads. The code tries to read a set of bytes from a URL and writes it to a random access file. Each threads writes to a different part of the file, hence the need for seek().
byte [] data =newbyte[1024];
int readLen;
while(canContinue && (readLen = bin.read(data)) != -1){
synchronized(dest){
dest.seek(start+completed);
dest.write(data, 0, readLen);
completed += readLen;
}
}
Now when the user pauses the download, canContinue is set to false. The problem with this scheme is that, it takes some time to pause all the download threads. How can I stop the downloads instantaneously?

