继上次weblogic和dwr集成的时候出现方法不能重载的问题之后,又出现了DWR又出事了,这次是DWRUtil.useLoadingMessage。红色的框框出现的提示一闪而过,以至于我不得不在n个地方做了修改,否则我只要改一个页面+新增一个javabean就搞定了。
但是莫名其妙的是,如果我新增了一个alert()函数,则没有问题,提示不会一闪而过。
从网上搜了一下,看来遇到的就是第三种情况
This method may be deprecated at some point in the future because its implementation has a number of limitations:
- The implementation is rather arbitary. Why red, why top right, etc. The only real answer is, to copy GMail.
- The action is supposed to stop the user interacting with the page until the remote call is complete, but this only works on Firefox due to limitations in IE (although this limitation is likely to be removed in version 3.0)
- This implementation will fail when multiple remote requests are outstanding - the message will be removed too quickly.
http://directwebremoting.org/dwr/browser/util/useLoadingMessage.html
思考一下,大概是由于dwr在运行的时候一个request是和一个dwr线程绑定的。而dwr的useLoadingMessage方法和我们写的javabean位于同一个线程。当javabean还没有执行完毕返回时,useLoadingMessage被阻塞在那里,知道javabean调用完成。
我写的页面中,在一个js的function中执行了2个dwr的javabean,其中一个执行速度很快,而另一个很慢,于是当执行速度快的javabean结束后,useLoadingMessage方法就返回了(dwr本身是异步的ajax,实际上两个javabean同时在后台跑)。
如果我使用了alert(),则可能造成了当第一个javabean返回后,useLoadingMessage方法被继续堵塞在那里,直到第二个执行慢的javabean执行返回。