201621123040 Java programming 11th Week of study summary

Source: Internet
Author: User

1. Study summary 1.1 This week summarize multithreading related content in the way you like (mind map or other).

2. Written work 2.1 Source code read: What is the use of multi-threaded bouncethread2.1.1ballrunnable classes? Why do I need to call in code Thread.sleepTo hibernate?
    • Implements the Runnable interface, displays the small ball position in each startup thread, realizes the small ball movement through the Component.repaint () method, the call Thread.sleep sleeps is to let the executing thread sleep for a period of time, does not consume the CPU resources
2.1.2ball.java only did two things, what are the two things? 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.javaDo two things--1) define the Move () function, determine the position transformation of the small ball, realize the movement of the small ball, 2) define the Getshape () function, determine the shape of the ball at the current position, Ballcomponent object--1) Add (ball B) adds the balls to be bounce; 2 Paintcomponent (Graphics g) Draws a small ball at each position, and its internal ArrayList is designed to record the balls added, and 1 Ballcomponent objects are generated during the program's operation, and the program uses multithreading techniques to Each ball is drawn in a different thread (Addball () in Ballthread.java () starts a new thread in the T.start ())
2.2 Experiment Summary: Topic set (Multithreading) 2.2.1 Title: Thread, Printtask, runnable, and anonymous inner class.

and answer: A) Runnable what is the benefit of implementing multithreaded programs by defining an implementation class for the interface, rather than implementing a multi-threaded program by inheriting from a Thread class? b) 6-1,6-3,6-11 experimental summary.

    • RunnableInterface implementation class to implement multithreading avoids the limitations of inheritance (a class can have multiple interfaces, but only one parent class)

    • 6-1 Experimental Summary :
      Write the Mythread class to inherit the thread, implement the definition of N in the class, and traverse the output 0~n-1 through the For loop; note that the last output is System.out.println(Thread.currentThread().getName()+" "+isAlive()) output only once and not nested in the For loop
      6-3 Experimental Summary :
      This is a review of the anonymous class, which outputs the main thread name, thread t1 thread name, thread T1 all interfaces implemented by the topic.
      6-11 Experimental Summary :
      And 6-1 have a certain similarity, the difference lies in the writing Printtask class inherits the Runnable interface

2.2.2 Using a lambda expression to overwrite 6-3

2.2.3 Title: 6-2 (runnable and stop thread). Answer: How do I need to properly stop a running thread?
    • Use the Stop () method to stop a thread, but its own flaw, forcibly terminating the thread, does not apply; With 6-2 exercises, we can implement a stop thread by writing the public void Stopme () method, which enables the boolean flag = true; thread to be safely stopped
2.3 Mutually exclusive access 2.3.1 modifies the Testunsynchronizedthread.java source code so that it can be accessed synchronously. (Key code, need to appear number)

2.4 Mutually exclusive access and simultaneous access 2.4.1 in addition to using the synchronized adornment method to achieve mutually exclusive synchronous access, what else can be achieved using synchronized to achieve mutually exclusive synchronous access, using code description (please show the relevant code and number)?
    • You can also use the synchronized (this) code block for mutually exclusive synchronous access

What is the difference between a 2.4.2 synchronous code block and a synchronization method?
    • Synchronized scope in a class that prevents multiple threads from accessing the class's synchronized static method at the same time, which works on all objects of the class
    • The synchronized (this) block scope is the current object, which means that only mutually exclusive access to the resource of the block is implemented
What is the principle of 2.4.3 for 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?
    • The principle of mutually exclusive access is to synchronize the lock on the shared resource, and the synchronized synchronous lock mechanism can be realized by using the modified method or code block. Guaranteed only one thread at a time to access resources
What keywords are used in 2.4.4Java multi-threading to implement the communication between threads, and to achieve the collaborative work of threads?
    • Synchronized keywords
    • volatile keyword
    • Wait method
    • Notify method
2.5 Collaboration between threads: Producer consumer issues 2.5.1 run 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?
    • Results are not normal, different times of the operation of the results of different operations, because the arrival of goods pickup speed inconsistent
2.5.2 Use synchronized, wait, notifySolve the problem (key code, need to appear number)

2.6 Object-oriented design job-Library Management system 2.6.1 system function module table, the table shows the owner of each module
Team member responsible for module
Lin Junwei Login interface
Wang Yaiyun Borrowing interface
Luojia Book Interface
2.6.2 Run the video 2.6.3 explain the module you are responsible for and paste the key code (the number and name) of the module you are responsible for. 3. Code cloud and PTA3.1 codes to submit records

3.2 "Multi-threaded" PTA Submission List

3.3 Count the amount of code completed this week of
Weekly total code volume New Code volume Total number new files
First week 189 189 10 10
Second week 304 304 9 9
Third week 557 557 10 10
Week Four 621 621 8 8
Week Five 326 326 7 7
Week Six 972 972 12 12
Seventh Week 338 338 4 4
Eighth Week 379 379 6 6
Nineth Week 492 492 5 5
Tenth Week 473 473 6 6
11th Week 527 527 10 10

201621123040 Java programming 11th Week of study summary

Related Article

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.