According to the context of the program, the Java keyword final has the meaning of "This cannot be changed" or "final state". It can modify non-abstract classes, non-abstract class member methods, and variables.
(1) The final class cannot be inherited, and there is no subclass. The methods in the final class are final by default.
(2) The final method cannot be overwritten by the quilt class, but can be inherited.
(3) Final member variables indicate constants and can only be assigned once. The values do not change after being assigned values.
(4) Final cannot be used to modify the constructor.
Note: The Private member method of the parent class cannot be overwritten by the quilt class method (of course, it cannot be inherited). Therefore, the private type method is of the final type by default.
========================================================== ========================================================== ======================================
(1) The synchronized keyword has two scopes:
A. In an object instance, synchronized amethod () {} can prevent multiple threads from simultaneously accessing the object's synchronized method, which is equivalent to running this method every time, check whether there are other programs that are using this method. If yes, wait until other programs run this method. If no, run directly (if an object has multiple synchronized methods, as long as one thread accesses one of the synchronized methods, other threads cannot simultaneously access any of the synchronized methods of this object ). However, the synchronized methods of different object instances are irrelevant. That is to say, other threads can access the Synchronized Method of another object instance of the same class at the same time.
B. The scope of a class. Synchronized static astaticmethod {} prevents multiple threads from simultaneously accessing the synchronized static method in this class. It canApplies to all object instances of the class.. Based on the above two points, we can conclude that synchronized modification indicates that the class lock is to be obtained before calling the static method, and that the object lock is obtained before calling the method in non-static method.
(2) In addition to using the synchronized keyword before the method, the synchronized keyword can also be used in a block in the method, indicating that only the resources in this block are mutually exclusive. Usage: private final object mlock = new object ();........... synchronized (syncobject) {/* block */}. Its scope is the current object, and syncobject can be a class instance or class (if the function where the code snippet is located is static, syncobject must also have static modification; otherwise, the system prompts "non-static variable ".
Syncobject cannot be referenced from a static context ).
(3) deadlock. Multiple code segments are locked for mutually exclusive execution. If a function in a synchronized (syncobject) code segment calls another function B, and function B also has synchronized (syncobject) code segment, which causes a deadlock. Because the two constrain the same syncobject.
Http://c.360webcache.com/C? Pipeline # 360sou
Http://www.blogjava.net/hongzionline/archive/2007/09/19/146392.html ()
Http://zhidao.baidu.com/question/68492173.html ()
Http://zhidao.baidu.com/question/106703762.html ()