Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
11,5 divide.java Mô-đun Mô-đun này phân chia nhiệm vụ thành các nhiệm vụ và trả về các mảng nhiệm vụ cho các module gọi. Các mã nguồn được trình bày trong hình. 11,8. 11,6 share2.java Module này khác nhau từ các share.java (Chương 9) trong những cách sau đây: r mới | 158 11. Power Server Model 3 Note that it is important to distinguish the differences between getNextNumber and getTaskNumber methods. The getNextNumber returns the number of next available sub-task but the sub-task is not assigned to the thread yet. On the other hand the getNextTask method returns the number next available sub-task and assigns it to the thread. The sub-task is assigned only when the server is ready to process it. 11.4.2.2 run Method In the run method the connection is checked by the following statement if connected return The sub-task is assigned by the following statement subTask answer.getNextTask The source codes of the addClientThread2 module are presented in Fig. 11.7. 11.5 divide.java Module This module divides the task into sub-tasks and returns the task array to the calling module. The source codes are presented in Fig. 11.8. 11.6 share2.java This module differs from the share.java in Chapter 9 in the following ways Two new methods are added i.e. getTaskNumber and getNextTask. The setGoAhead method is removed as this synchronization is not required. The following are the functions of the new methods getTaskNumber return the next available task number to the calling thread. getNextTask assign and return the next available sub-task number to the calling thread. The source codes of this module are presented in Fig. 11.9. 11.7 Testing Programs can be tested in a similar way to Sections 6.5 and 6.6. Again I would recommend that you start with one computer even if you have several computers in front of you. Testing 159 import java.io. import java.util. public class divide double x long endPosition long totalTasks boolean debug public divide double x long endPosition long totalTasks boolean debug if debug System.out.println divide module this.x x this.endPosition endPosition this.totalTasks totalTasks this.debug debug public void go long width endPosition totalTasks dividing job into sub-tasks for int i 0 i x.length i i 2 if i 0 x i 1 else x i x