0

I implemented a download manager, which works fine except that I noted one thing, sometimes the thread blocks for a while(50 milliseconds to up to 10 seconds) when writing to files, I am running this program on Android(Linux based), my guess is if there're some kind of buffer in the OS level that needs to be flushed, and my writing actually writes to that buffer, and if that buffer is full, writing needs to wait.

My question is what is the possible reason that could cause the blocking?

4

2 に答える 2

3

IO is well known to be a 'blocking' activity, hence your question should be 'what should you do while your program is busy waiting for IO to complete'

Adopting some of the well known concurrency strategy and event-based programming pattern is a good start

于 2012-12-24T03:32:16.727 に答える
0

- I have done the writing and reading of files in the following way and never encountered any probs.

Eg:

File f = new File("Path");
FileWriter fw = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(fw);

- You can alternatively try out the NIO package in Java.

于 2012-12-24T02:23:10.673 に答える