Is ImageIO write() a blocking method?

2019-02-25 12:05发布

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条回答
再贱就再见
2楼-- · 2019-02-25 12:46

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

查看更多
登录 后发表回答