java - How to wait in the same thread while file is being written to, to finish, so we can use it -


i have file open , write situation crashes eofexception once in 20-30 times, because file unavailable because other process writing it.

can catch exception, somehow wait file write operation synchronously end, can recurse method?

file productjson = getfilestreampath("product" + "_" + getid() + ".json"); if (!productjson.exists()) {     productjson = getfilestreampath("product" + ".json"); }  inputstream jsonstringsfileinputstream; try {     jsonstringsfileinputstream = new fileinputstream(productjson);      hashmap<string, map> = new jsontoproductparser().convertthistothat(jsonstringsfileinputstream);  } catch (filenotfoundexception e) {     e.printstacktrace(); } 

you can check file write access before opening it.this done canwrite() method.

oracle docs - file # canwrite

also check out solved question. deals synchronized attribute.

solved question - synchronized


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -