201621123018 Summary of the 11th Zhou of Java programming

Source: Internet
Author: User

1. Summary of this week's study

1.1 Summarize multithreading related content in the way you like (mind map or other). 2. Written work

Multi-thread of this PTA job title set

1. Source code reading: What is the use of multi-threaded BounceThread1.1 ballrunnable classes? Why do I need to call Thread.Sleep to hibernate in my code?
    • BallRunnable类Can implement runnable interface, it supports multithreading
    • This is to delay the completion of the thread to see the motion trajectory of the ball.

      1.2 Ball.java only do two things, what are the two things respectively? What does the Ballcomponent object do? What is the use of the ArrayList inside? How many ballcomponent objects are generated during the program run? The program uses multithreading techniques, each of which is drawn in separate threads? Ball.javatwo things to do:
    • Control the movement of the ball
    • Get the size and coordinates of a ball

    • BallcomponentThe object adds a new ball and draws a small ball.
    • ArrayListUsed to store small balls
    • Generate an BallComponent object
    • is drawn in a different thread.

      2. Experiment Summary: Problem sets (multithreading)
2.1 Topics: Thread, Printtask, runnable, and anonymous inner classes.

and answer: A) What is the benefit of implementing multithreaded programs by defining the implementation class of the Runnable interface than by inheriting from the thread class? b) 6-1,6-3,6-11 experimental summary.

6-1thread

As long as run() the value of the output can

6-11printtask

The subject is similar to 6-1, except that the identity information is different

6-3runnable and anonymous inner classes

The subject according to the requirements of the topic is one step at a.

-### 2.2 Using a lambda expression to overwrite 6-3

    Thread t1 = new Thread(() -> {        System.out.println(mainThreadName);        System.out.println(Thread.currentThread().getName());        System.out.println(Arrays.toString(Thread.class.getInterfaces()));    });
2.3 Title: 6-2 (runnable and stop thread). Answer: How do I need to properly stop a running thread?
    • You can use the stop() method
    • You can define a flag to terminate, to exit the thread

      3. Mutually exclusive access
3.1 Modify the Testunsynchronizedthread.java source code so that it can be accessed synchronously. (Key code, need to appear number)

4. Mutually exclusive access and synchronous access

Complete episode 6-4 (mutually exclusive access) with 6-5 (synchronous access)

4.1 In addition to using the synchronized modification method to achieve mutually exclusive synchronous access, what else can use synchronized to achieve mutually exclusive synchronous access, using code description (please show the relevant code and number)?

4.2 What is the difference between a synchronous code block and a synchronization method?

The synchronous code block is locked inside the method, the synchronization method is locked on the whole method, the range is different

4.3 What is the principle of implementing mutually exclusive access? Use the object lock concept and describe it in conjunction with the corresponding code block. How does the state of the thread change when the program executes the synchronized synchronous code block or synchronous method?

Principle: Lock a shared resource so that only one thread is allowed to access it within a given time.

4.4 What keywords are used in Java Multi-threading to implement communication between threads, so that threads work together?
    • Wait ()
    • Notify ()

      5. Inter-Threading cooperation: producer-consumer issues
5.1 Run the Myproducerconsumertest.java. The result of the normal operation should be 0 goods left in the warehouse. Run multiple times, observe the results, and answer: Is the result normal? What's not normal? Why?

Not normal, there may be goods left, because inventory and pickup speed is not the same

5.2 Use synchronized, wait, notify solve the problem (key code, need to appear number) 6. Object-oriented design job-the Function module table of the Library Management System 6.1 system, the table shows the owner of each module. 6.2 Run the video 6.3 Explain the module you are responsible for, and paste the key code of your own module (the number and name appears). 3. Code Cloud and PTA

Topic Set: Multithreading

3.1. Code Cloud codes Submission record

In the Code cloud Project, select statistics-commits history-set time period, and then search for and
Several elements must appear: Submit Date-user name (name and school number)-no instructions

3.2 "Multi-threaded" PTA Submission List

Two graphs are required (1. Ranking chart. 2.PTA Submission list diagram)

3.3 Count the amount of code completed this week
Week Time Total code Amount New Code Volume total number of files number of new files
1 160 160 49 49
2 387 227 55 6
3 630 243 59 4
4 968 238 65 5
5 1171 203 69 4
6 1626 445 77 8
7 2061 435 80 3
8 2385 324 86 6
9 2727 342 90 4
10 3038 311 97 7
11 3123 85 104 7

The weekly code statistics need to be fused into a single table.

201621123018 Summary of the 11th Zhou of Java programming

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.