I have the following piece of code
public String ls() throws IOException, InterruptedException {
String pwd = getPWD();
String inodePath = "Upload/Files" + pwd + "inode";
// Request the inode file first
Peer.setFileReceivedCheck(false);
Inode i = new Inode();
i.requestInode(pwd + "inode");
boolean fileCheck = Peer.getFileReceivedCheck();
System.out.println(fileCheck);
while (fileCheck == false) {
System.out.println(); // DOES NOT WORK IF THIS LINE IS REMOVED!!
fileCheck = Peer.getFileReceivedCheck();
}
System.out.println(fileCheck);
return i.readFromInode(inodePath);
}
In the above java method, the fileCheck
variable keeps track of when a file is downloaded from the network and becomes true
when the file download completes; so that the functions returns when the file download is completed.
The weird problem which I am facing is that if I remove the above line (the one with just a println); the method is stuck in the while loop and does not return even though the file has been downloaded! Any idea as to why this is happening?
EDIT: This is not running in a separate thread. The file download code in another class (Peer.java
) is running in a separate. Again, the getter for fileCheck is out of the thread.