Reputation: 8135
I have an small app that write data to file then reading back data,
writeData();
readData();
but it seems that readData() is executed before WriteData() finished its execution, is there any away to wait for writeData()?
Thank you very much.
Upvotes: 1
Views: 166
Reputation: 1392
Try to call the flush and close operation on the OutputStream you are using.
outputStream.flush();
outputStream.close();
If you are working in the main thread and it still doesn't update, maybe your inspection of the value is delayed? Is it UI-based and you don't update the UI?
The code of your writeData() and readData() operations could give more insights for solving the problem :)
Upvotes: 0
Reputation: 4313
Reentrant lock is your best bet. And here's a relevant example.
http://www.carfey.com/blog/java-concurrency-part-2-reentrant-locks/
Upvotes: 2