OO Second Summary-multithreading

Source: Internet
Author: User

OO Fifth Job-multi-threaded elevator

  1. Job Analysis

This job and the first two different is the use of multithreading, but also introduced the thread of security problems, to this job caused some trouble. Because of the use of multi-threading, you can not use the first two ways, the request all input and then the related calculation, need to run side of the calculation, so abandoned the first two architectures, basically re-start planning this job. The method of simulating time and the model of producer consumers are used to construct public object request queue as a pallet, scheduler and request input thread respectively as consumers and producers.

2. Operation class Diagram

  

3. Measurement analysis

  

Sure enough scheduler class and elevator class method or need to comb, if and other logic nested a bit more, resulting in a high degree of complexity.

4. Bug Analysis

This time there are two bugs. First, because there are a few paragraphs of the code is similar, directly copied over the result forgot to modify some of the variable names, resulting in the judgment of the problem, second, the main instruction at the end of the critical condition of the back of the decision to forget, resulting in additional instructions.

These two bugs are minor changes, which is one line of code that ignores these details when it's written. is also because of some slack, qingming holiday out wave a lap, back when hurried to finish the homework. You should pay attention to it later.

OO Sixth job-monitoring files

  1. Job Analysis

This job is no longer the elevator (from this time to take the elevator no longer worry about), but become a directory file monitoring. But also because of this, this job on the thread security requirements have become higher, unlike the fifth multi-threaded elevator as there is not much need to pay attention to security issues.

This time a total of 4 triggers 3 tasks, I follow a trigger with a task way of the thread, so there will be a maximum of 3*4*10=120 threads. But also because of this, when dealing with recover and record, there are some reasonable situations in the way that the JVM handles multithreading. According to the instructions, a Safefile file security class has been constructed to make the unsafe files class from Java safe.

This task is not very difficult to think, not like the elevator to consider a lot of situations, only need to regularly scan the good, the only thing to pay attention to is the thread of security issues, as long as this aspect of the treatment of the basic will not appear problems.

2. Operation class Diagram

  

3. Measurement analysis

  

Overall, the complexity is OK, or for, if, switch and so on too many nested, if these judgments split into a method and feel that there is no need, tangled.

4. Bug Analysis

Two bugs were found this time. First, because the operation contingency format to the input relaxed requirements, no use of regular, also forget try-catch, resulting in the input irregularities will be crash, sure enough or not to relax the vigilance ah; the second is the thread security problem, because the Safefile class creates objects, I create a new object directly, regardless of whether the object of the file before this path has been created. This leads to the synchronization in my safefile is useless in the test thread, because the Safefile object in the test thread is completely new, and the time of the lock release is not controlled during the scan, and the files that have been scanned during the entire scan should not release the lock. Otherwise, the scanned files will be changed during the scanning process and problems may occur.

Although the bug was found, but still feel that they did not lose anything, after all, from the tester learned the process of thread safety knowledge, it is equivalent to the score for knowledge, not loss.

Oo Seventh assignment-Taxi

  1. Job Analysis

This is the beginning of a large-scale taxi operation (never take a taxi again), and not as the elevator from the single-threaded, but directly from the multi-threaded start, but with the first two of the foundation, plus this is the first time the taxi operation, the difficulty is not particularly large.

I was looking for a taxi to design, every request to open a thread, to find a taxi can grab a single, while each taxi is also a thread, to carry out related movements. So the taxi object is a public object that needs to be locked to prevent the request thread and the taxi thread from manipulating the taxi object at the same time. After the request thread runs 3s, it filters out the most suitable taxis from the taxi list and assigns the request, in which case it is necessary to lock the taxi object and prevent other request threads from changing the state of the taxi.

2. Operation class Diagram

  

3. Measurement analysis

  

Observation, the complexity of the several methods are written by their own bfs, there are try,if,while,for,switch nested, resulting in a high degree of complexity, but the same is the BFS, it is not necessary to take BFS to split, so it is retained.

As for the schedule method in the Taxischeduler class, it is indeed possible to split. The first part of the code is put in a method, but later modified, there is no way to open a separate method ..... or because of laziness.

4. Bug Analysis

This time I did not find any bugs. When I tested my own code, I found a bug that caused the output to output a few things, and later found out that it was the reason for wait () and sleep () to use the error, but instead of releasing the lock, I freed the lock with wait () and removed the bug after changing to sleep ().

Experience

  I have to say, Oo brought me a lot of pressure than the group, so that people tired, exhausted. But in this high-pressure environment, but also really learned a lot of knowledge, can only say that there are pros and cons of it. It is said that after the work of OO is not as difficult as before, but I always feel that is cheating people, not to mention the Nineth week began in Wednesday there is metalworking practice, a thought up on the heart tired. Although tired, but when you hand over the homework did not find the bug when it is also valuable to feel tired. Just do it and cherish the time of OO.

OO Second Summary-multithreading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.