1. Study summary 1.1 This week summarize multithreading related content in the way you like (mind map or other).
2. Written work this time PTA job title set multi-thread 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?
Answer: 1, Function: It realizes the Runnable interface.
2, because this class in the run () method so that the ball can move, call Thread.Sleep to sleep is to improve the efficiency of the program operation.
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 makes # # #用了多线程技术, each ball is drawn separately in different threads?
Answer: 1, control the movement of the ball and get the position and shape of the ball.
2. Add () to the ball object, and draw the component that added the ball object.
3, ArrayList function: The realization of variable array and all optional list operation.
4. Two Ballcomponent objects are generated.
5, not.
2. Experimental Summary: Title set (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.
A: Because the runnable is suitable for multiple threads of the same program code to handle the unified resources, the thread is separated from the code of the program and the data is effective, which can better embody the object-oriented design idea.
2.2 Using a lambda expression to overwrite 6-3
2.3 Title: 6-2 (runnable and stop thread). Answer: How do I need to properly stop a running thread?
A: The most basic way to end a thread: the Thread.stop () method or use the Thread.Interrupt () method
3. Mutex Access 3.1 Modify the Testunsynchronizedthread.java source code so that it can be accessed synchronously. (Key code, need to appear number) 3.2 Choose to do: further use of actuators to improve the corresponding code (key code, need to appear number) Reference: Java multi-thread executor, Executorservice, executors, callable, Future and FUTURETASK4. Mutually exclusive access and synchronous access complete set 6-4 (mutually exclusive access) and 6-5 (synchronous access) 4.1 In addition to using the synchronized adornment method to achieve mutually exclusive synchronous access, there is still a way to implement mutually exclusive synchronous access using synchronized, Use code description (please show the relevant code and number)?
4.2 What is the difference between a synchronous code block and a synchronization method?
A: The synchronization method uses the synchronized adornment method to lock, the lock's scope is larger, while the synchronous code block can refer to some code inside, its lock scope is relatively small, thus the performance is better.
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: 1, principle: The object holds the object only the lock can be thread, not allow other threads of the task to disturb, and the rest of the thread no object lock in the lock pool, waiting for the end of the thread.
2. Change of state: Multiple threads run, one thread gets object lock run--and the rest waits for one thread to end, the remaining threads compete for object locks until all threads run end.
4.4 What keywords are used in Java Multi-threading to implement communication between threads, so that threads work together?
A: Use Wait () and notify ()/nofityall () to communicate between threads.
5. Collaboration between Threads: Producer consumer issues 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?
Answer: The result is not normal, because the multiple runs found the goods still have surplus, the normal situation should be 0.
Public synchronized void Add (String t) and public synchronized void remove () should have the Wait () and notify () functions in the body of the method to implement the cooperation between the threads. Otherwise, multiple threads are simply not mutually exclusive, but do not cooperate, resulting in a result error
5.2 Use synchronized, wait, notify solve the problem (key code, need to appear number)
6. Object-oriented design job-Library Management System 6.1 system of the functional modules table, the table reflects 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
The weekly code statistics need to be fused into a single table.
Week 11--java Multithreading