JSP and JavaBean
JSP development portal (Author: IDEAL at 18:15 on August 10, 2000)
Although you can file in small orders Add a large piece of the code, but most of the Java programming code are reusable components can be called JavaBean. ActiveX controls JavaBean told the same: they provide the known function, and is ready to repeat the use of the purpose of design.
JavaBean value is that it may be able to use a group of properties, and these properties will provide access to JavaBean set. For example to the people, this person is JavaBean, and his name, social welfare safety numbers, and addresses can be characteristics. The JSP web site, you will be basically 'JavaBean' dynamic linking to your site.
JavaBean assumption in the establishment of the website is built, you want to do the first thing is to tell it to use JSP page JavaBean. This work can be used <jsp: useBean> tag to complete: <jsp: useBean id = " localName "class =" com.jguru.Person "scope =" application "/>.
<jsp:useBean> Label id attributes you need to identify beans. Here, you provide a name for JSP page to identify beans, in addition to id attribute, you must also tell the website to Daonailiquhua beans, or It is the Java category name. Attribute types provided in the various methods of how to find it, the final component is a necessary attribute scope. Attributes with the help of the scope, you can tell beans, it should be a single page (the default) [scope = "page" ;] as a requested web page [scope = "request"]; calls for the period of [scope = "session"]; or for the entire application process [scope = "application"] to safeguard its own information, the terms of the scope of calls , you can easily JSP page in the maintenance of the project, such as Cart.
But you declaration of a JavaBean, you can access it on the characteristics of setting it. To achieve a value of the properties, the use of <jsp: getProperty> tags. With <jsp: getProperty> tag, you can specify the name to be used beans (from the id useBean field), and you want to obtain value of the properties. Then, the real value will be on the output of: <jsp: getProperty id = "localName" property = "name" />.
To change the characteristics of JavaBean, you need to use <jsp: setProperty> tags. On the label, you also need to identify the beans as well as the characteristics of that, in addition, you also need to provide a new value. Naming If correct, these can be directly in the format specified by: <jsp: setProperty id = "localName" property = "*" />;
Parameters obtained from one, you have to direct this feature, as well as named parameters: <jsp:setProperty id="localName" property="address" param="parameterName" />;
Or directly to the name and the value set: <jsp:setProperty id="localName" property="serialNumber" value="string" /> or <jsp: setProperty id = "localName" property = "serialNumber" value = < %% = expression> />.
JavaBean the final point: let JavaBean network server can be found, you will need the type of files on the special place. JSWDK on, the simplest places in the installation directory, the directory of categories, such as \ jswdk-1.0.1 \ classes.
"Expert One-on-One J2EE Development without EJB" Douhougan
—-** In 2006/01/14
Heard "Expert One-on-One J2EE Development without EJB" has been a very long time. However, as time has been very tight, (mainly did not have time), this does not present a good opportunity to read the book carefully.
In this semester final exams finished, a lot of time on their own, so in the last few days in this book a good read.
This book is the English version. Read a bit difficult. But also good exercise their abilities.
Read after they found their ability Chatache the. The author's vision of capacity. Gave me great inspiration.
The author J2EE development on all aspects, including the realization of the various layers, as well as the shortcomings of their existence,
At the same time give some solutions. As described in the author at the same time, the light of their own experience in the exposition, there are also a lot of advantages and evidence.
In the web layer, the major way to achieve this, as well as their shortcomings and correct programme.
In the middle layer, the realization of any major, as well as their shortcomings and correct programme.
In the persistence layer, the major way to achieve this, as well as their shortcomings and correct programme.
EJB caused by the use of the consequences. EJB use of the main field. SLSB use. Spring used EJB or other alternative technologies provided by the service.
EJB caused by the introduction of the complexity and difficulty in testing, and other issues.
IoC the introduction of the powerful advantage.
AOP the introduction of the powerful advantage.
TDD (Test Drivren Development) benefits, as well as how to provide better application development based on the test.
……
Through a lot of technology, the introduction of open source products. The author's views are certainly a lot of people agree, although some of the practical implementation of standards will affect product development. However, the author can be seen in the language, the author's aim is to develop better maintainability, testability better, more simple applications. Rather than a product provider or deny the unilateral introduction. Can be seen from the starting point is right. I believe in the near future, Rod Johnson will leave you better know.
Look forward to. In the hope that he can better development of the J2EE to the author of the study, all the best people to learn. Let their products more outstanding.
Have fun!
In fact, the habit of using python write some single-threaded expansion, has not encountered such problems
Write a python today in the extension of the time encountered a problem. Through the python launched a c + + thread, the thread c + + will be a pullback python interface. Debugging has been for a long time is not aware of the security thread reasons, because c + + threads in the vm call python when the pyobject. thread is not safe. Therefore, when c + + threading operation vm directly to a certain object it is very wrong result.
I search the information in the http://www.python.org/dev/peps/pep-0311/ have talked about how the vm synchronous python. Two vm lock function can be done, and c + + thread synchronization. Is The so-called GIL (Global Interpreter Lock).
There are two ways to accomplish the following:
1. Py_BEGIN_ALLOW_THREADS, Py_END_ALLOW_THREADS this to Acer
2. PyGILState_Ensure and PyGILState_Release
But I Py_BEGIN_ALLOW_THREADS not seem useful, I will not have to get to the bottom, because PyGILState_Ensure enough. Do not have too much time to study the documents, to use the time to look back on.
I look at the sample code:
# Include "Python.h"
# Include "ceval.h"
Class PyGILHelper
(
Public:
PyGILHelper ():
MState (PyGILState_Ensure ())
(
)
~ PyGILHelper ()
(
PyGILState_Release (mState);
)
Protected:
PyGILState_STATE mState;
);
Usage is simple:
PyGILHelper lock;
/ / Some c api code
Package org.kyle.net.svr.sample;
Public class IntegrationFactory
(
Public IntegrationFactory ()
(
)
Public static IListener createListener (GenProfile genCfg)
(
IListener iListener = null;
Try (
/ / Configuration file set up under the category creates corresponding examples
IListener = (IListener) instantiateIt (genCfg.getListenerImpl ());
)
Catch (Exception e) (
Debug.info ( "Listener class not found!");
/ / If the designated categories do not exist, use the default category to create examples, as well as because of the procedure used in the interface are therefore here to provide a default category invoked, the compiler compiler, and only mainclass, the need for a separate again the compiler default category
IListener = new SampleListenerImpl ();
)
Return iListener;
)
/ / In accordance with the category names are examples of
Public static Object instantiateIt (String clsName)
Throws ClassNotFoundException,
ClassCastException,
InstantiationException,
IllegalAccessException
(
Class cls = Class.forName (clsName);
Return cls.newInstance ();
)
)
In the configuration file, add the following: Listener = org.kyle.net.svr.sample.SampleListenerImpl
JMF capture technology (audio)
JMF can capture voice and video equipment, also can be controlled by means of the JMF Mike, these audio and video camera equipment, to be discussed here is how to make use of JMF Mike, in their own tests on the machines, let you hear their own voices.
Below is related to the main categories:
CaptureDeviceManager, CaptureDeviceInfo, Vector, MediaPlayer, DataSource, MeidaLocator, AduioFormat, VideoFormat, Format.
Sun can be provided in the Document on the inspection can be down under, the site not remember. Can be looked at, there was a preliminary understanding, and then return to read examples of class libraries, this might be better.
Public class CaptureDeviceManager
Extends java.lang.Object
CaptureDeviceManager is a manager class that provides access to a list of the capture devices available on a system. CaptureDeviceManager uses a registry and query mechanisms to locate devices and return CaptureDeviceInfo objects for available devices. The CaptureDeviceManager is also used to register new capture devices.
Public class CaptureDeviceInfo
Extends java.lang.Object
Implements java.io.Serializable
A CaptureDeviceInfo object contains information about a particular capture device.
Public class MediaPlayer
Extends java.awt.Container
Implements Player, java.io.Externalizable
MediaPlayer encapsulates a player in a JavaBeans TM component. MediaPlayer implements the Player and Externalizable interfaces.
A MediaPlayer can be used as a full-featured Player with either the default Player controls or custom controls.
Also involves a monitoring interface:
ControllerListener. This is mainly used to monitor the media player interface.
1, capture audio equipment
/ *
* @ Author: kenny
* /
Import javax.media .*;
………………..
(Public class CaptureAudio
Vector deviceList = new Vector ();
AudioForamt audio = new AudioFormat (AudioFormat.LINEAR);
Format audioFormat = (Format) audio;
MediaPlayer player = null;
MediaLocator locator = null;
CaptureDeviceInfo captureInfo;
Public CaptureAudio () (
DeviceList = CaptureDeviceManager.getDeviceList (audioFormat);
CaptureInfo = (CaptureDeviceInfo) deviceList.get (0);
CaptureInfo.getLocator locator = ();
)
Public void play () (
Player = new MediaPlayer ();
Player.setMediaLocator (locator);
Player.addControllerListener (this);
Player.realize ();
)
Public void controllerUpdate (ControllerEvent e) (
If (e instanceof RealizeCompleteEvent)
Player.prefetch ();
If (e instanceof PrefetchCompleteEvent)
Player.start ();
)
Public static void main (String [] args) (
CaptureAudio audio = new CaptureAudio ();
Audio.play ();
)
)
When multiple threads are interacting with an object, controls need to be in place to ensure that the threads don't adversely affect one another. This chapter deals with issues that can introduce subtle errors in your application. An application that fails to safely control concurrent access can work properly most of the time-maybe nearly all the time - but will occasionally produce erroneous results. This makes the understanding and disciplined use of the information in this chapter critical to writing truly thread-safe applications that work properly all the time.
If you have a system in a baffling problem, is likely to visit with the issue of Oh
Volatile Member Variable Modifier
The
Java Language Specification indicates that for optimal speed, individual threads are permitted to keep a working copy of shared member variables and only reconcile them with the shared original occasionally. To be more accurate, the word "occasionally" in the last sentence should be replaced with "when a thread enters or leaves a synchronized block of code." I'll tell you more about synchronized blocks later in this chapter. When only one thread is interacting with the member variables of an object, this optimization works very well and can allow for faster execution. When two (or more) threads are simultaneously working with an object, care must be taken to ensure that changes made to a shared member variable by one thread are seen by the other.
Java specification that, in order to optimize speed, each thread with all members sharing a copy of variables, when the beginning or end of a thread synchronization code block, only to write the variable values. When single-threaded, the good work of such a mechanism will be entitled to higher performance, but a number of threads to work together, consideration must be given by a thread change public variable to be aware of other threads.
The volatile keyword is used as a modifier on member variables to force individual threads to reread the variable's value from shared memory every time the variable is accessed. In addition, individual threads are forced to write changes back to shared memory as soon as they occur. This way, two different threads always see the same value for a member variable at any particular time. Chances are that most of you expected this behavior from the Java VM already. In fact, many experienced Java developers don't understand when the use of volatile is necessary.
Volatile keywords, if modified to members of variables, each thread is forced to visit each variable must be re-read, each change variable values to be written as soon as possible. In this way, two different threads in a specific time can be the same as the total value of the variable
Use volatile on member variables that can be accessed by two or more threads unless all the threads access the variables within synchronized blocks of code. If a member variable remains constant after construction (it is read-only), there is no need for it to be volatile.
If a member variable is read-only, there is no need to set up volatile
If a visit this thread all the variables are in a synchronized block, there is no need to set volatile
The volatile modifier exists to request that the VM always access the shared copy of the variable. This is less efficient than allowing the VM to perform optimizations by keeping a private copy. You should use volatile only when it is necessary; overuse will unnecessarily slow the application's execution.
Volatile requirements of each virtual machine on the request of variables to visit, for each thread to maintain a private copy is inefficient and will lower speed access, such as non-essential, do not use
Synchronized Method Modifier
The addition of the synchronized modifier to a method declaration ensures that only one thread is allowed inside the method at a time. This can be useful in keeping out other threads while the state of an object is temporarily inconsistent.
Synchronized modification, modification of a method used to declare that can guarantee the same time there is only one thread can call this method.
Such a mechanism to prevent objects in a continuous state was no other threads visit
Two Threads Simultaneously in the Same Method of One Object
If two or more threads are simultaneously inside a method, each thread has its own copy of local variables.
Two or more threads at the same time call the same object in the same way, each thread has a copy of the local variables
One Thread at a Time
More than one thread can be inside a method, and each thread keeps a copy of its own local variables. However, there are times when application constraints require that only one thread be permitted inside a method at a time.
When a thread encounters a synchronized instance method, it blocks until it can get exclusive access to the object-level mutex lock.
Mutex is short for mutual exclusion. A mutex lock can be held by only one thread at a time. Other threads waiting for the lock will block until it is released. When the lock is released, all the threads waiting for it compete for exclusive access. Only one will be successful, and the other threads will go back into a blocked state waiting for the lock to be released again.
Guarantee the same time there is only one thread invoke a method, simply stated before the synchronized method. When a thread encountered Affirms that the method sychronized example, will be blocked until it was object-level mutex lock signal of access, at a certain moment mutex signal can only be a thread with other waiting for the signal The thread must wait for the signal to be released this mutex lock release, other threads access to competition, the success of threads running other threads continue to wait for the obstruction to release the mutex lock.
Two Threads, the Two Objects
Every instance of a class has its
own object-level lock.
Although the doStuff () method is synchronized, there is no competition for exclusive access to the object-level lock. Each instance, obj1 and obj2, has its own object-level lock. When threadA enters the doStuff () method of obj1 (line 1), it acquires exclusive access to the object-level lock for obj1. When threadB enters the doStuff () method of obj2 (line 3), it acquires exclusive access to the object-level lock for obj2.
Examples of each object has its own object-level locking. In other words, the lock is built on the synchronized object instance, and not the object of the abstract. Call the same number of threads examples of an object with a synchronized way, the visit will be synchronized, and call the same number of threads examples of the different groups with a synchronized way, it is not mutually exclusive of mutual visit.
Avoiding Accidental Corruption of an Object
It's an unavoidable fact that the object must be in an inconsistent state for a brief period of time, even with everything except the assignments taken out:
Public synchronized void setNames (String firstName, String lastName) (
Fname = firstName;
Lname = lastName;
)
No matter how fast the processor is, it's possible that the thread scheduler could swap out the thread making the changes after it has changed fname but before it has changed lname. Holding an object-level lock does not prevent a thread from being swapped out. And if it is swapped out, it continues to hold the object-level lock. Because of this, care must be taken to ensure that all reads are blocked when the data is in an inconsistent state. CleanRead (see Listing 7.16) simply adds the synchronized method modifier to getNames () to control concurrent reading and writing.
Two threads at the same time calling a method of amending certain examples of variable values, values of these variables will lead to a moment in the state is not continuous, synchronized with modified this method, can guarantee that the integrity of this variable value
Deferring Access to an Object While It Is Inconsistent
Calling a thread in a synchornized value of the modification to set a example of the value of certain variables, only restriction other threads at the same time calling this method, does not restrict other threads calling other means of access these variables, if At this point another thread in the value of the call was a way to visit these variables, some variables may have been modified, and also some other variables have not changed, and may cause variable is discontinuous.
Will be worth Xiuchifu synchronized with the former method, solve this problem. This is because there is only one example of a target object-level locking, when a synchronized method is called, the examples of other synchronized methods must await the release of this lock.
If two or more threads might be simultaneously interacting with the member variables of an object, and at least one of those threads might change the values, it is generally a good idea to use synchronized to control concurrent access. If only one thread will be accessing an object, using synchronized is unnecessary and slows execution.
Synchronized Statement Block
The synchronized block can be used when a whole method does not need to be synchronized or when you want the thread to get an object-level lock on a different object.
Synchronized block Scope
1, not the entire synchronization methods are needed
2, need to lock the different target
The synchronized statement block looks like this:
Synchronized (obj) (
/ / Block of code
)
Where obj is a reference to the object whose object-level lock must be acquired before entering the block of code.
This setPoint () method
Public synchronized void setPoint (int x, int y) (
This.x = x;
This.y = y;
)
Can be rewritten to instead use a synchronized block:
Public void setPoint (int x, int y) (
Synchronized (this) (
This.x = x;
This.y = y;
)
)
The behavior of both versions of setPoint () is virtually the same. They do compile to different byte-code, but both of them make sure that they have exclusive access to the object-level lock for the instance before making changes to x and y .
Reducing the Time That the Lock Is Held
A synchronized block can be used to reduce the time that the object-level lock is held. If a method does a lot of other things that don't require access to the member variables, it can shorten the time that it holds the lock to just the critical portion:
Public void setValues (int x, double ratio) (
/ / Some other, the long-running statements that don't work
/ / With the member variables go here.
/ / …
Double processedValA = / / … long calculation …
Double processedValB = / / … long calculation …
/ / …
Synchronized (this) (
A = processedValA;
B = processedValB;
)
In setValues (), exclusive access to the object-level lock is not needed until the time-consuming calculations have been made and the results are ready to be stored. At the bottom of the method, the object-level lock is acquired and held briefly to simply assign new values to the member variables a and b.
Reduce lock time, only in this way the need for synchronization of locking, and the youngest of locking overhead
Locking an Object Other Than this
A non-locking the object of this
The reference mutex indicates the object whose object-level lock must be acquired before entering the statement block. It can be a reference to any object in the VM, not just this. Regardless of how a thread leaves a synchronized block, it automatically releases the lock. This includes a return statement, a throw statement, or just falling through to the next statement after the block. Calling a method from within the synchronized block does not constitute leaving the block (the lock is still held).
Virtual machine can be synchronized with any object, not just this.
Sometimes you will need to call two synchronized methods on an object and be sure that no other thread sneaks in between the calls. Consider this code fragment from a class called Bucket:
Sometimes two synchronized methods must be implemented simultaneously
Public class Bucket extends Object (
/ / …
Public synchronized boolean isSpaceAvailable () (/ / …
Public synchronized void add (BucketItem o)
Throws NoSpaceAvailableException (/ / …
Public synchronized BucketItem remove () (/ / …
/ / …
)
A call:
Bucket b = / / …
/ / …
If (b.isSpaceAvailable ()) (
B.add (item);
)
This is fine if only one thread is interacting with this instance of Bucket. But if multiple threads are potentially trying to add BucketItem objects to the same Bucket, a new approach has to be taken to avoid a race condition. Imagine that threadA checks and sees that space is available, but before it actually adds its item, threadB checks and also sees that space is available. Now threadA and threadB are racing to actually add an item. Only one can win the race, and that thread gets to add its item . The other thread will fail to add its item and will throw a NoSpaceAvailableException. To prevent this problem, a synchronized block should be wrapped around the two method calls:
This method only when a thread is correct, otherwise they will be in sync errors
Bucket b = / / …
/ / …
Synchronized (b) (
If (b.isSpaceAvailable ()) (
B.add (item);
)
)
The synchronized block uses the object-level lock on b, the Bucket instance. This is the same lock that must be acquired before entering the isSpaceAvailable () and add () methods. If a thread can get the object-level lock and enter the synchronized block, it is guaranteed to be able to invoke isSpaceAvailable () and add () without blocking. Because it already has the object-level lock for b, there is no delay or competition to enter the synchronized methods. In addition, no other thread can invoke these methods until the first thread leaves the synchronized block.
To the code on a b-lock, the other threads can call b synchronized in any way, once a thread was a b lock, the lock will certainly implementation of the code, there are no other threads competition
Static synchronized Methods
In addition to the object-level lock that exists for each instance of a class, there is a class-level lock that all instances of a particular class share. Every class loaded by the VM has exactly one class-level lock. If a method is both static and synchronized, a thread must get exclusive access to the class-level lock before entering the method.
The class-level lock can be used to control concurrent access to static member variables. Just as the object-level lock was needed to prevent data corruption in non-static member variables, the class-level lock is needed to prevent corruption of static member variables. Even when no variables are involved, the synchronized modifier can be used on static methods simply to ensure that only one thread is inside the method at a time.
Object-level lock correspond to each category of case
Class-level lock all categories corresponding to the example of virtual machine generated each category there is a class-level lock, for a static synchronized method, this method before calling, threading his visit will Pai class-level lock.
Using the Class-Level Lock in a synchronized Statement
The synchronized statement can also use a class-level lock. This can be useful if a static method runs for a long period of time. Additionally, it can be used to ensure that two static method calls by one thread are not interleaved with a call by another thread.
To lock on the class-level lock, use the following code
Synchronized (ClassName. class) (
/ / Body
)
Class-Level Lock used to block synchronization code, the use of synchronized (class names. Class) ()
Synchronization and the Collections API
Vector and Hashtable were originally designed to be multithread-safe. Take Vector, for example - the methods used to add and remove elements are synchronized. If only one thread will ever interact with an instance of Vector, the work required to acquire and release the object-level lock is wasted.
Vector and Hashtable initially designed as a thread-safe, most of them are synchronized method, in the single-threaded process is unnecessary
The designers of the Collections API wanted to avoid the overhead of synchronization when it wasn't necessary. As a result, none of the methods that alter the contents of a collection are synchronized. If a Collection or Map will be accessed by multiple threads, it should be wrapped by a class that synchronizes all the methods.
Collections are not inherently multithread-safe. Extra steps must be taken when more than one thread will be interacting with a collection to make it multithread-safe.
Collection API designed for the time when the need for synchronized, the default is not thread-safe, if in a multi-threaded environment using Collection, we must first convert it into thread-safe
There are several static methods in the Collections class that are used to wrap unsynchronized collections with synchronized methods:
Public static Collection synchronizedCollection (Collection c)
Public static List synchronizedList (List l)
Public static Map synchronizedMap (Map m)
Public static Set synchronizedSet (Set s)
Public static SortedMap synchronizedSortedMap (SortedMap sm)
Public static SortedSet synchronizedSortedSet (SortedSet ss)
Collections provide several static method to be used for non-security thread pool thread-safe set for the conversion, above, apply as follows:
Basically, these methods return new classes that have synchronized versions of the collections' methods. To create a List that is multithread-safe and backed by an ArrayList, use the following:
List list = Collections.synchronizedList (new ArrayList ());
When synchronizing collections, do not keep any direct reference to the original unsynchronized collection. This will ensure that no other thread accidentally makes uncoordinated changes.
In order to ensure synchronization sets, not directly using the initial non-thread-safe set.
Safely Copying the Contents of a List into an Array
List three ways to copy an array safety
Safely Iterating Through the Elements of a Collection
Ergodic pool safety, traversing the time to prevent other threads add or modify data collection
The elements of a Collection can be stepped through one by one by using an Iterator. In a multithreaded environment, you will generally want to block other threads from adding or removing elements while you are iterating through the current collection of elements.
Deadlocks
Using locks to control concurrent access to data is critical to avoid subtle race conditions within applications. However, trouble can arise when a thread needs to hold more than one lock at a time.
Control the use of lock mechanism with access critical data when a thread lock at the same time have more than two problems may arise: Deadlock
Deadlocks can be extremely difficult to track down. Generally, most of an application will continue to run, but a couple of threads will be stuck in a deadlock. To make matters worse, deadlocks can hide in code for quite a while, waiting for a rare condition to occur. An application can run fine 99 out of 100 times and only deadlock when the thread scheduler happens to run the threads in a slightly different order. Deadlock avoidance is a difficult task.
Most code is not vulnerable to deadlocks, but for the code that is, try following these guidelines to help avoid deadlocks:
L Hold locks for only the minimal amount of time necessary. Consider using synchronized statement blocks instead of synchronizing the whole method.
L Try to write code that does not need to hold more than one lock at a time. If this is unavoidable, try to make sure that threads hold the second lock only for a brief period of time.
L Create and use one big lock instead of several small ones. Use this lock for mutual exclusion instead of the object-level locks of the individual objects.
L Check out the InterruptibleSyncBlock class in Chapter 17. It uses another object to control concurrent access to a section of code. Additionally, instead of having a thread block on the synchronized statement, the thread is put into a wait-state that is interruptible. I'll tell you more about the wait-notify mechanism in Chapter 8.
It is hard to avoid deadlock, the following general principles can reduce the possibility of deadlock
L lock the shortest possible time, to make full use of synchronized statement as a whole rather than synchronized methods
L at the same time try not to have more than one lock, if unavoidable, should be guaranteed a second thread lock the shortest possible time
L establishment of the use of a big lock, rather than a number of small lock, with a new large object lock ghostwriters all the small lock
Chapter 17 gives InterruptibleSyncBlock l category, it uses another object code block to control concurrent access. Do not let a thread synchronization in a statement, obstruction, but may be interrupted at the wait state, the next chapter will discuss the use of the wait-notify mechanism.
Speeding Concurrent Access
To speed up execution, do not use synchronized unnecessarily. Be sure that it's really needed for proper functioning. If synchronization is necessary, see if using a synchronized statement block would work instead of a synchronized method. Although this won't decrease the cost of acquiring and releasing the lock, it will reduce contention for the lock among the other threads because the lock is held for a shorter period of time.
Accelerate the speed of synchronization visit:
1, such as non-essential, does not apply synchronized
2, the use of synchronized statement block can not use synchronized method will reduce the probability of conflict
Summary
In this chapter, I showed you:
L How to use volatile to force unsynchronized threads to work with the shared copy of a variable instead of a private working copy.
L How to use the synchronized method modifier on non-static methods to require a thread to get exclusive access to the object-level lock before entering the method.
L How to use the synchronized statement block to require a thread to get exclusive access to the object-level lock of the specified object before executing the code within the block.
L How to use the synchronized method modifier on static methods to require a thread to get exclusive access to the class-level lock before entering the method.
L How to work safely with the Collections API in a multithreaded environment.
L How to understand the causes of deadlocks, and how to try to avoid them.
Guarantee the use of multi-threaded Xiuchifu volatile variables simultaneously
Guarantee the use of synchronized Xiuchifu examples of an object in the object-level lock on the synchronization