Java Week 12th Job

Source: Internet
Author: User
Tags set time thread class

1. This week study summary 1.1 summarizes the set of related content in the way you like (mind map or other).

1.1.1 Please explain the difference between thread class and runnable interface for multithreading
    The
    • thread class inherits from the Runnable interface, is a subclass of the Runnable interface, and implements multithreading using the Runnable interface to avoid restrictions on single inheritance
    • It is more convenient to realize the concept of data sharing by using Runnable interface to realize multithreading.

      1.1.2 Hibernate
    • Thread.CurrentThread usage similar to this, used to get the currently executing thread object
    • thread.sleep () mostly sleep, feel like sleeping together, There are actually a few minor differences.
    • The higher the priority of the thread object, the more may execute first

      2. Written work

      This job title multithreading

      2.1. Source code reading: What is the use of multi-threaded BounceThread2.1.1 ballrunnable classes? Why do I need to call Thread.Sleep to hibernate in my code? The purpose of the
    • Ballrunnable class is to implement the Runnable interface so that it can be received by thread and invoke the start () method to launch the thread. The
    • is useful for observing the motion trajectory of multiple balls, and if you do not add hibernation, the thread will end up showing only the final position of the ball, and you will not see the running trajectory

      2.1.2 Ball.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.java Two things to do: 1. Move the ball 2. The plane coordinates of the return ball
    • The Ballcomponent object is used to add a small ball and draw a small ball out of the
    • internal ArrayList for storing small ball objects The
    • program generates only one Ballcomponent object during its run.
    • When you click the Start button, a small ball movement is generated per click, and each ball is drawn in a different thread.

2.2. Experiment Summary: Title set (multithreading) 2.2.1 Title: Thread, Printtask, runnable, and anonymous inner class.

a) Runnablewhat 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?

    • The thread class inherits from the Runnable interface, is a subclass of the Runnable interface, and implements multithreading with the Runnable interface to avoid the restriction of single inheritance
    • It is more convenient to realize the concept of data sharing by using Runnable interface to realize multithreading.

b) 6-1,6-3,6-11 experimental summary.

    • 6-1: Inherit the method from the class by creating a class Thread that inherits it start() , and then satisfies the problem by covering the run() method.
    • 6-11: Similar to 6-1, but through the implements keyword implementation Runnable interface, and overwrite the method to achieve the requirements of the run() topic
    • 6-3: This method is more concise than the first two by creating an anonymous thread object and an anonymous Runnable interface object and new Thread(new Ruannble(){}) then covering the method in the form of an anonymous inner class run()

      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?
    • By declaring a Boolean variable flag to control run the run, here, if flag is true to stop, false to proceed, you can create a STOPME () method to modify the value of the flag variable.

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 synchronous access

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

2.4.1 In addition to using the synchronized modification method to achieve mutually exclusive synchronous access, what can be achieved using synchronized to achieve mutually exclusive synchronous access, using code description (please show the relevant code and number)?
    • You can also implement mutually exclusive synchronous access via synchronization blocks

What is the difference between a 2.4.2 synchronous code block and a synchronization method?
    • Synchronous code block: The use of keywords within a method and the acquisition of the synchronized (this) current thread object, and then synchronous operation, is implemented inside the method
    • Synchronous method: The method is declared by means of the synchronized keyword, so that it can be called when the method is synchronous operation.

      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?
    • By using synchronized keywords, so that when the thread to use this part of the program, to lock the program, at this time if there are other threads to access the content needs to wait for the lock to be unlocked, when the use of the threads after the operation, the lock is unlocked, at which time other threads can access.

    • Just as the result of this code runs, it is only after the a thread has finished executing that it can perform a sell-ticket operation on another thread.

      2.4.4 What keywords are used in Java Multi-threading to implement communication between threads, so that threads work together?
    • Synchronized keywords
    • wait,notify Keywords and Volatile keywords

      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?

    • The result of the operation is not normal, the results show that when the warehouse is full during the operation, the operation of adding the goods cannot be carried out but still count, so the last remaining goods are not 0.

      2.5.2 use synchronized, wait, notify to solve 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 reflects the owner of each module. 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 PTA

Topic Set:多线程

3.1 Yards cloud Code submission record
    • In the Code cloud Project, select statistics-commits history-set time period, and then search for and

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

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

Week Time Total code Amount New Code Volume total number of files number of new files
1 120 120 2 2
2 280 160 5 3
3 590 310 10 5
4 780 190 12 2
5 1290 510 17 5
6 1710 420 20 3
7 2513 803 24 4
8 2513 0 24 0
9 3014 501 27 3
10 3441 327 30 3
11 4121 680 37 7
12 4667 546 42 5

Java Week 12th Job

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.