Is ImageIO write() a blocking method?

浪尽此生 提交于 2019-12-02 00:04:22

问题


In an application I'm developing in java, I am using the ImageIO API to scale images, then write them to a directory and then inform a web server that the images are ready to be used. The last call before sending a signal to the web server is the method ImageIO.write() but the web server cannot find the generated images at that moment. ( Few milliseconds latter the web server is able to see them. ).

What I suspect is that ImageIO.write() is running asynchronously. I've searched a lot but i couldn't find if ImageIO.write() is a synchronous or asynchronous operation. If ImageIO.write() is not blocking the flow of the program, is there a non-hacking way to make it wait till the image has been written to the destination directory ?


回答1:


I can't imagine that ImageIO.write isn't blocking.

My "assumption" is based on the fact that ImageIO.write can throws exceptions, which suggests, even if it as writing in the background, it would need to block until the write was finished in order to throw the exceptions.

It could be a buffering issue?

Try and do a while (!file.exits()) Thread.sleep(25) or something has a stop gap



来源:https://stackoverflow.com/questions/11842674/is-imageio-write-a-blocking-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!