Threading Learning Summary :
- thread is a single execution stream
- The difference between program one and program two is that when a program has an action, the user's operation will be queued, can not run at the same time two actions, program two can also be realized the concurrency of the program.
- New thread has two methods: 1. Implemented with an interface. 2. Inherit the thread class.
- broken thread: The last statement was executed or an exception was caught during execution. The thread terminates, giving the CPU the right to use.
- The state of the thread is 7 see P635 need to be aware of the relationship between each state, You can change the state of a thread when you call any method. (thread state implements thread rotation using CPU)
- getname () Get thread name getpriority () get priority
- competitive use CPU when the dynamic execution characteristics of threads, concurrency, the full use of resources. shared resources and competition for memory.
- program is divided into four modules ( ball, ballcomponent,bounceframe,bounce)
from Ball Class (new 2d ellipse, defined Move method)
Ballcomponent Class ()
The bounce program should be queued for the user's actions, the event will respond to the next, the program serial,
The Bouncethread program, executed with thread threads, is defined as the thread, concurrency of the event response action in Addball
- There are two ways to implement a synchronization mechanism:
1. Synchronize code blocks:
Synchronized (same data) {} same data: N thread accesses one data at the same time
2, synchronization method:
Public synchronized Data Return type method name () {}
1, objects of this class can be accessed by multiple threads safely.
2, after each thread invokes any method of the object, it will get the correct result.
3, after each thread invokes any method of the object, the object's state remains in a reasonable state.
201671010130 2016-2017-2 Java Programming 17th Week of study summary