The future model can be simply viewed Proxy Mode And Thread-per-message mode In the proxy mode, a proxy is used to replace the real object (subject) generation. The generation of the target may be time-consuming. For example, in an embedded image file, it is hoped that the program can enable the file as soon as possible and display an acceptable picture to the user. On the page that does not need to see the image, use the proxy to replace the real image loading, the proxy object loads the real image only when you really need to see the image. In this case, the user may quickly browse the file through pages, and the image file is very large. When browsing the page number of images, it will cause the image to be loaded, as a result, the user may pause when browsing the file, so we hope that after the file is opened, there will still be a background job that will continue to load images, so that the user can quickly browse the page, the pause may be improved. In the future mode, when a request occurs, a future object is first generated to the requesting customer. It acts like a proxy object, and at the same time, the real target object is generated, A new thread-per-message (thread-per-message) is executed continuously. After a real target object is generated, it is set to future. When the client really needs the target object, the target object is ready for extraction and use by the customer. A simple Java program snippet demonstration may look like this: .... Public future request () { final future = New Future (); New thread () { Public void run () { // The following actions may be time-consuming realsubject subject = new realsubject (); future. setrealsubject (subject); } }. start (); return future; } |