是的ImageIO的write()阻塞的方法是什么? [英] Is ImageIO write() a blocking method?

查看:1131
本文介绍了是的ImageIO的write()阻塞的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我用Java开发,我使用的ImageIO API缩放图像的应用程序,然后将其写入到一个目录,然后通知Web服务器,该图像是随时可以使用。将信号发送到Web服务器之前的最后的呼叫​​是方法ImageIO.write(),但在Web服务器不能找到在那个时刻所生成的图像。 (几毫秒后的Web服务器能够看到它们。)

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. ).

我怀疑的是,ImageIO.write()是异步运行。我搜索了很多,但我找不到,如果ImageIO.write()是一个同步或异步操作。如果ImageIO.write()没有阻止程序的流程,有没有一种非入侵的方式,使其等到图像已被写入到目标目录?

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 ?

推荐答案

我无法想象, ImageIO.write 未阻止。

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

我的假设,是基于这样的事实,ImageIO.write可以抛出异常,这表明,即使它在后台写入,就需要阻止,直到写在以抛出的异常结束。

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?

试着做了而(!file.exits())视频下载(25)或某事有一个权宜

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

这篇关于是的ImageIO的write()阻塞的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆