I am trying to make a download manager. I am using a class download that will do most of the work and will allow you to use multiple connections like FlashGet or the like.
Here is a proof of concept class that copies a file using more than one thread at the same time. The only problem I have is that I can't figure out how change the number of threads after download.
Current algorithm:
1) Call to copy()
2) It makes x amount of Threads using Thread(this) and runs them
3) Check if the length of the destination file is set - set it
4) Divide the file length by the number of threads; multiply this by the id of the thread and you get the end position ; id -1 for the start postion
5)Synch on the file and seek to the current position
6)Read
7)Synch on the other file and seek to the current position
8)Write
9)Go to 5 till you have read till stop
Anyone got any ideas on how to allow it to resize the partitions and add/remove threads?