The code of frame of process of multi-line Cheng application that implements Runnable interface is shown as follows:
/ / Consumer.java
Import Java.util. *;
Class Consumer Implements Runnable
{
……
Public Consumer(int NTime, string StrConsumer){……}
Public Void Run(){……}
Static Public Void Main(String Args[] )
{
Thread AConsumer = New Thread(new Consumer(1000, "AConsumer" ));
AConsumer.start();
/ / the moving line Cheng of other object example
/ /……
}
}
Can see from afore-mentioned code: This kinds realized Runnable interface and in this kinds in defined Run method. The implementation means of process of application of Cheng of this kind of multi-line and successive Thread kind the methodological design method that the important distinction of process of multi-line Cheng application depends on starting multi-line Cheng boy or girl friend is different. In afore-mentioned code, through founding Thread object example and application the object serves as found Thread kind the parameter of example.
4, the synchronism between line Cheng
The many lines Cheng of Java application process shares the data resource of same process, many subscribers feeder Cheng are in and the likelihood in sending moving process visits the content that has sensitivity at the same time. The idea of line Cheng synchronism was defined in Java, implementation is safeguarded to sharing the consistency of resource. Below the mobile that develops recently with the author method of the synchro control between Cheng of central line of plan fee system, the implementation process of means of synchronism of Cheng of the multi-line in showing Java language.
The client account that issueing without condition of multi-line Cheng synchro control strategy kind definition frame code is shown as follows:
Public Class ReGISterAccount
{
Float FBalance;
/ / client capture expends a method
Public Void Deposit(float FFees){FBalance = FFees; }
/ / communicate plan cost method
Public Void Withdraw(float FFees){FBalance -= FFees; }
……
}
The reader perhaps can think: Afore-mentioned program code can satisfy the need with plan fee real system completely. Really, this order issueing in single-track Cheng environment is reliable really. But, is much progress intercurrent is the condition that run what kind of? Produce this kind of situation suppose: The client is using mobile device while client service center undertakes capture is expended only this communicates, the client communicates system of end chronometer fee starts plan cost process, and at the same time the staff member of the service center also refers capture to expend a process to move. If produce this kind of situation,the reader can see, it is not earnest to the processing of client account.
Previous 1 2 3 45 6 7 8 Next