Hi,there's a problem with my progress monitor:It never ends!
First,I got this class of myself:
public class PrintProgressMonitor implements FTPProgressMonitor {
private long currentTransByte=0;
private long fileSize=0;
private double percentage=0;
public static final long CHUNK_SIZE=1024;
public PrintProgressMonitor(long fileSize) {
this.fileSize = fileSize;
}
public PrintProgressMonitor() {
this.fileSize = 0;
}
public void bytesTransferred(long byteTransferred) {
this.currentTransByte = byteTransferred;
this.percentage=((double)byteTransferred/(double)fileSize)*100;
}
public boolean transComplete() {
if(percentage==100) {
return true;
}
else {
return false;
}
}
}
Then,somewhere during my code,I wrote following code:
while(!progressMonitor.transComplete()){
Thread.sleep(100);
System.out.println("Plese wait while file being transferred");
}
The program runs well in most cases,but sometimes it hangs on infinite loop. I check the byte length already transferred,it never reached the full file size,thus causing the program hang.
For example:the file has 1000.It always shows that 995 has already been transferred,but on remote ftp,I can see the file is already there.
Why there is such a problem with progress monitor?