Position:Home>JAVA Development> The blemish of Java line Cheng
The blemish of Java line Cheng
From;  Author:Stand originally

Task (the task) concept

The basic problem of model of Java line Cheng is it not be object-oriented completely. Object-oriented (OO) design personnel presses line Cheng angle to consider an issue far from; What they consider is information of synchronous information asynchronous (synchronous information is handled instantly- - till information processing the ability that finish returns a message sentence handle; Period of time handles backstage after asynchronous information is received- - and early return a message before information processing ends sentence handle) . The Toolkit.getImage() method in Java programming language is a of asynchronous information good example. The message of GetImage() sentence the handle will be returned instantly, and need not when whole picture by tiring-room line Cheng resumptive.

This is object-oriented (the processing technique of OO) . But, the place before be like is narrated, the dispute of line Cheng model of Java is object-oriented. Cheng of line of programming language of a Java is process of a Run() only actually, it called the procedure of other. Do not have object, asynchronous or synchronous information and other concept at all here.

To this problem, a means of settlement that has discussed deep in my book is, use an Active_object. Active object is the boy or girl friend that can receive asynchronous to request, after it is inside the period of time after receiving a request, stand way is able to handle. In Java programming language, a request can be enclosed in an object. For example, you can pass the example that Runnable interface realizes conveys this Active object, the Run() method of this interface enclosed the work that need completes. This Runnable object is emited into by this Active object in alignment, when be turn for it to carry out, active object uses Cheng of line of a tiring-room to carry out it.

The asynchronous message that runs on an Active object is synchronous actually, because they are served onefoldly by,line Cheng is taken out from inside alignment by order and carry out. Accordingly, use an Active target with a kind more the synchronous issue that the model that the process turns can remove great majority.

In a sense, the whole Swing/AWT subsystem of Java programming language is an Active object. The way of the exclusive safety that sends a message to biographies of team of a Swing is, call the method of a similar SwingUtilities.invokeLater() , sent object of a Runnable on Swing incident alignment so, when be turn for it to carry out, swing incident handles line Cheng to will handle it.

So the first my proposal is, join a Task to the middle of Java programming language (the task) concept, thereby Active object compositive in the language. (The concept of Task is the RMX operating system from Intel and Ada programming language are drawn lessons from those who come over. Operating system of most real time supports similar idea. )

A task has inside the Active object of buy issues an order, manage those automatically to handle the whole mechanism of asynchronous information.
Previous 1 23 4 5 6 7 8 9 10 11 12 13 Next