OO second summary blog

 

Fifth assignment:

Class Diagram:

Metric graph:

Collaboration diagram:

Analysis: Multi-threaded elevator implementation in this operation. The first time I came into contact with multithreading, I didn't think too much about it. I directly used threads to complete the information exchange and information storage between threads, which caused many errors in the program at the beginning, and even could not run. According to the metric graph, it can be seen that too much code is written in the run method of the thread. And some of these codes should be owned by another non-threaded class. The role of the thread should be to transmit data to achieve synchronization, and should not store too much data to modify data.

Bug: Due to the deviation of the multi-threaded design idea, many unpredictable bugs appeared in this job. In the process of mutual testing, the code of the other party is divided into many modules. Non-threads store data, while thread classes carry out information transmission and data changes, avoiding excessive interaction between threads and better achieving synchronization. However, due to logic problems, the code of the other party will crash when the piggybacked instruction is executed in a certain situation.

Sixth homework:

Class Diagram:

Metric graph:

Collaboration diagram:

Analysis: There is not much interaction between the job threads this time, and multiple monitoring objects monitor different or the same directory tree. According to the metric graph, my code is too cumbersome to compare two snapshots, and I only use it as a method. This code with specific functions is best written as a class or thread to increase the clarity of the code.

The seventh assignment:

Class Diagram:

Metric graph:

Collaboration diagram:

Analysis: This job is to simulate a taxi call system. At first, my idea was that the car is instructed to calculate the route, but the time required for such calculation is even close to the time of each grid movement of the car, which will cause the operation of the entire system to lag. . In the end, I can only calculate these paths when the map is initialized and use it at runtime. The random path selection method of the car I wrote is too complicated, there should be a very simple algorithm, but I have not thought of it for the time being. The run method is complicated and still an old problem. Some functions are not extracted into non-thread classes or thread classes for use. The structural division of labor should be more reasonable.

Bug: The bug in this assignment is mainly a time issue. For example, the calculation takes too long and there is a problem with the time. Or the wrong car was ordered after the window ended, because the information of the car was not updated correctly after the window ended, resulting in a lag in information.

Summary: Multi-threaded jobs are very complex and difficult. In the design, it is necessary to construct a class system with a clear division of labor, such as thread-safe classes that only save data, certain thread classes that transmit information, and thread classes that implement some specific methods. Wait. I hope that in the continuous practice in the future, I can master the design method of multi-thread safety and write more efficient code more reasonably.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325162241&siteId=291194637