201621123042 Java Programming 11th operations

Source: Internet
Author: User
Tags set time what debugging

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

This PTA work problem set多线程

1. Source code reading: Multi-threaded Bouncethread

What is the use of the 1.1 ballrunnable class? Why do I need calls Thread.sleep to hibernate in my code?
A: Ballrunnable class, realizes the Runnable interface, realizes the move and the repaint method in the Run method, realizes the small ball trajectory.
Call Thread.Sleep is for the thread to hibernate, delaying the completion of the thread, so that you can see the movement of the ball, if you do not call the Thread.Sleep method, then the small ball will be in a short period of time to end the motion trajectory, unable to view its state.

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?
For:
Ball.java did two things. Move () method to achieve small ball movement, getshape () to obtain the size of the ball coordinates.

The Ballcomponent object is implemented by adding small balls, and drawing a small ball.

Adding a small ball will start a new thread, so each ball is drawn in its own thread.

1.3 : program rewrite: When the program runs, each ball is set from a fixed position. How do you rewrite the program so that when you click Start, each ball can be moved from a different position, with a different step?

1.4 : The moving track of different balls is exactly the same. The transformation process, so that each small ball trajectory is not exactly the same, for example, some can take the cosine trajectory, some can go square wave trajectory, some go Brownian motion, some go pentagram, and so on.

2. Experiment Summary: Problem sets (multithreading)

2.1 Topics: Thread, Printtask, runnable, and anonymous inner classes.

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.
For:
Benefit: A class can inherit only one parent class, but it is possible to implement multiple interfaces. And the running interface is suitable for resource sharing.

6-1 Experimental Summary: This problem requires num to be passed in, rewrite the Run method, and finally print the identifier.

6-3 Experimental Summary: This topic needs to start thread T1 in the main method and print three lines of information.
mainThreadName
Thread.currentThread().getName()
Arrays.toString(getClass().getInterfaces()
Print the main thread name individually, the thread name of T1, and all interfaces implemented by T1.

6-11 Experimental Summary: This is the Printtask class implementation runnable interface, in the Run method output 0-n-1 integer.

2.2 Using a lambda expression to overwrite 6-3
For:

2.3 Title: 6-2 (runnable and stop thread). Answer: How do I need to properly stop a running thread?
A: This question tells us to stop a thread that cannot use the Stop method, because if the thread is forced to terminate in half when it is executed, it is generally terminated with a Boolean variable when we need to stop a thread, while(!flag) Statement to terminate a thread by changing the value of a Boolean to cause the while to exit the loop.

2.4 Selected: 6-8 (countdownlatch) Experiment Summary
2.5 Select: 6-9 (set synchronization problem) experimental summary
2.6 Choose: More difficult: 6-10 (callable), and answer why Runnable need callable? Experimental summary.

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)
For:

3.2 Optional: Further use of the actuator to improve the corresponding code (key code, need to appear number)
Reference : Java multi-thread executor, Executorservice, executors, callable, future and Futuretask

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)?
For:

4.2 What is the difference between a synchronous code block and a synchronization method?
A: The synchronous code block is not declared synchronized before the method name, but synchronized is declared before the block of code to be shared.

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?
A: When one thread is working, it blocks another thread from working.

The state of the thread changes:
When the program executes the synchronized synchronous code block, it first obtains the object's internal lock, if not obtained, enters the wait pool, waits until the internal lock is released, then enters the lock pool again to run, if obtains the internal lock in the beginning directly enters the lock pool, then runs.

4.4 What keywords are used in Java Multi-threading to implement communication between threads, so that threads work together?
Answer: Wait and notify keywords.

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?
A: This is because the producer and the customer's access speed is not the same, the two can not communicate, resulting in an abnormal number of goods.

5.2 Use synchronized, wait, notify to solve the problem (key code, need to appear number)
For:

5.3 : use lock with the condition object to resolve the problem.

6. Object-oriented design job-Library management system

6.1 The system's functional modules table, which reflects the owner of each module.

6.2 Running the video

6.3 Explain the module you are responsible for, and paste the key code of your own module (the number and name of the school).

7. Select: Use other methods to solve the problem of producer consumers of topic 5.

7.1 Using BlockingQueue key code to resolve producer consumer issues
7.2 explains why you do not need to display the use of wait, notify to resolve synchronization issues. What are the advantages of wait and notify to solve this problem?
7.3 Use condition to solve the problem of producers and consumers.

8. Choose: Write a piece of code to prove that you will use FORKJOINPOOL.9. Optional: Unit Test JUINT4

Topic 6: Unit tests using JUNIT4.
Use JUNIT4 to compare the sort time of two sorting algorithms and.

3. Code Cloud and PTA

Topic Set:多线程

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

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 44 44 2 2
2 213 213 10 5
3 417 204 10 5
5 676 259 17 7
6 1071 50T 24 7
7 1780 709 30 6
8 1900 120 35 5
9 2335 435 41 6
10 2767 432 48 7
11 3321 595 57 9
12 3601 280 63 6
4. Optional: Extracurricular reading

4.1

Java Concurrent Animated
4.2

Advanced Knowledge Notes for Threads
4.3

Questions and Exercises:concurrency, learn to summarize.
4.4

Java multi-thread executor, Executorservice, executors, callable, future and Futuretask
4.5

Thread pool, this one might be enough.
4.6

Java 8 Concurrency Tutorial:threads and executors

5. Choose: Learn to debug with Eclipse

Watch related Debug Videos
5.1 Briefly how many steps do I need to debug with eclipse? When debugging F5, F6, F7 fast key each have what different? What is the shortcut key to use?
5.2 Experimental Task Book topic 5: Using Eclipse for debugging 5.1, how to use the debugging features of Eclipse to find out when reading "Blue Mountain Blue" This line does not go wrong?
5.3 Task Book 5.2, proving that you will use conditional breakpoints.
5.4 Choose: Debug the System in the Messageboard.zip until it is ready to function. Explain how you found the error in the system? What debugging techniques are used?
References: Some debugging Tips for Eclipse

201621123042 Java Programming 11th operations

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.