Define a task and definition kind basic and identical, the different allocation that an Asynchronous adds to decorate accord with to indicate Active boy or girl friend before just needing the method in the task program backstage handles these methods. Consult please of the 9th chapter in my book be based on kind of method, see the following File_io again kind, it used in " Taming Java Threads " in the Active_object of place discussion kind will realize asynchronous to keep an operation:
All writing in requesting to use process of a Dispatch() to call the input formation that is put in Active-object, queue up. When backstage handles these asynchronous information, appear any unusual (Exception) is handled by Exception_handler object, this Exception_handler object is conveyed in the tectonic function of File_io_task. When you should keep content to the file, code is as follows:
This kind is based on kind processing technique, its are main the problem is too complex- - to a so simple operation, code is too miscellaneous. After introducing $task and $asynchronous key word to Java language, can press the face rescripts so the code previously:
Attention, asynchronous method did not assign return of value, because of its sentence the handle will be returned instantly, and need not when after the operation processing of the request is finished. So, do not have reasonable return of value right now. To the model that derive gives, $task key word and Class are the same as effect euqally: $task can come true interface, successive kind with successive other task. Mark has the method of Asynchronous key word to be handled by $task backstage. The method of other runs synchronism, resemble be in kind in same.
$task key word can be decorated with an optional $error subordinate clause (as above place shows) , it makes clear right any what cannot be caught by asynchronous method itself is unusual will have default processing program. My use $ will represent the unusual target that is cast to go out. If did not appoint $error subordinate clause, will print give to make mistake reasonably information (probable it is stack dogs information) .
Attention, to ensure line Cheng is safe, the parameter of asynchronous method must be changeless (of Immutable) . The system when moving should assure this kind of fixity through relevant semantics (duplicating simply is insufficient normally) .
All Task objects must bear message of a few bogus (Pseudo-message) , for example:
Besides commonly used got-up accord with (the) such as Public, task key word still should accept a $pooled(n) to decorate accord with, it brings about Task to use pool of Cheng of a line, is not to use single line Cheng to run asynchronous request. N specified the size that wants line Cheng pool; When necessary, pool of this line Cheng can increase, but when should needing line Cheng no longer, it should shrink original size. Bogus region (Pseudo-field) $pool_size returns the primitive N parameter that appoints in $pooled(n) to be worth.
Previous 1 2 34 5 6 7 8 9 10 11 12 13 Next