to collection through a single lock, and the cost is poor scalability. In other cases where multiple threads are expected to access public collection, it is generally better to have a "concurrent" version. Non-synchronous collection is better when collection is not shared, or collection is accessible only when other locks are kept.Most concurrent Collection implementations, including most Queue, are also different from regular java.util conventions because their iterators provide weak consisten
. Therefore, to realize the visibility of volatile variables, you can start from this aspect. There are two main differences between the write operation on volatile variables and normal variables:
(1) When you modify the volatile variable, the modified value is forcibly refreshed in the primary memory.
(2) modifying the volatile variable will invalidate the variable value corresponding to the working memory of other threads. Therefore, when you read the variable value, you need to read the value
the thread to do the appropriate operation. This is also the essential cause of data invisibility between threads. Therefore, in order to realize the visibility of volatile variables, we can start with this aspect directly. There are two main differences between write operations for volatile variables and ordinary variables:
(1) Modifying the volatile variable will force the modified value to be refreshed in the main memory.
(2) Modifying the volatile variable causes the value of the correspo
of semantics in that passage.
Guaranteed visibility, no guarantees of atomicity
Prohibit command reordering
The first layer of semantics is not introduced, the following emphasis on instruction reordering.In order to improve performance when executing a program, the compiler and processor usually reorder the instructions:
The compiler resets the ordering. The compiler can rearrange the execution order of the statements without changing the semantics of the single-thre
Prohibit command reordering
The first layer of semantics is not introduced, the following emphasis on instruction reordering.In order to improve performance when executing a program, the compiler and processor usually reorder the instructions:
The compiler resets the ordering. The compiler can rearrange the execution order of the statements without changing the semantics of the single-threaded procedure;
The processor is re-ordered. If there is no data dependency, the proc
, this standard has strict restriction. This evaluation criterion is limited to questions raised in this way, such as "If I do this, what will happen" such problems can be examined by observation experiments. Questions such as "Should I do this" and "what is the value of this matter" do not belong to scientific questions that can be examined by observing experiments.However, if a proposition is not a proposition of science, and it is not able to accep
reordering
The first layer of semantics is not introduced, the following emphasis on instruction reordering.In order to improve performance when executing a program, the compiler and processor usually reorder the instructions:
The compiler resets the ordering. The compiler can rearrange the execution order of the statements without changing the semantics of the single-threaded procedure;
The processor is re-ordered. If there is no data dependency, the processor can change the
Store1 and later. 4,storeload such as Store1 storeload load1 ensure that the Store1 data is visible to other threads of other processors (flushed to memory) before the LOAD1 and subsequent data load instructions. The memory access instruction after the barrier is executed before the memory instruction (load and store) is executed. NBSP;JVM has these four memory barriers to effectively control the reordering. But this understanding and use is more troublesome. jdk1.5 the memory model used later,
. ReentrantLock will be much better than synchronized, the source code implementation of ConcurrentHashMap uses the ReentrantLock to improve concurrency security and efficiency.Iv. Happens-Before rulesTo ensure that thread A sees the operation result of thread B (whether or not A and B are executed in the same thread), the relationship between A and B must satisfy the Happens-Before relationship. The Happens-Before rules are as follows:Program Order Rule: if operation A in A Program is prior to
ordered, and if one thread observes another, all operations are unordered.4. First occurrence principle (Happens-before)
The main basis for determining whether or not the data is competitive and whether the thread is secure.1. Rules of Procedure Order: in a separate thread, the operation is performed Happen-before (time) after the execution of the program code, in the order in which it is executed.2. Manage locking rules: A unlock Operation
named serialversionuid, variables of the long type can be serialized or deserialized to each other without modifying the serialization entity of the variable value.
If you do not consider compatibility issues, turn it off, but this function is good. If serializable is implemented in any category, if serialversionuid is not added, eclipse will give you a warning that this serialversionuid is backward compatible for this type of serializable.
Question 1: if there are two serialversionuids that ar
+wt/st) threads to keep the processor fully utilized Happen-before:In order to improve multithreaded performance, the compiler will reorder the code, based on the Happen-before rules, to determine the sequence of code execution.1. Single-threaded rule: In the same thread, write in the previous operation Happen-before write in the following operation. This rule i
1. The "Black Swan" in software testing
A few years ago, I led a Test team to omit a serious bug to the Internet, when the user feedback the bug, we analyze it deeply and reproduce it, and ultimately everyone agrees that it is a coincidence that this bug can happen because it requires multiple conditions to occur at the same time to trigger it, such as " XX algorithm switch must be opened, XX algorithm switch must be closed, XX parameters must take a
read saw a non-coherent phenomenon caused by records inserted by other transactions. 1. Transaction A is not logged when querying records. 2. Transaction B inserts the record and submits it. 3. Transaction A records that were inserted by transaction B when querying records again. is not the feeling and non-repetition read a bit like Ah, focus on the insert operation or update operation. In addition, the following is also the Phantom read OH 1. Transaction a statistical records are X-pieces. 2.
example, most compilers reject inline "complex" functions (such as cyclic and recursive functions); and, even the simplest virtual function call, the compiler's inline handler cannot help it. (This is not surprising. Virtual means "Wait until the runtime to decide which function to call", inline means "Replace the called place with the called function during compilation ", if the compiler does not even know which function will be called, it cannot be blamed for rejecting inline calls ). The abo
called place with the called function during compilation ", if the compiler does not even know which function will be called, it cannot be blamed for rejecting inline calls ).
4: Problems and Corresponding Solutions
Assume that a function f is written and declared as inline. If the compiler decides not to inline it for any reason, what will happen? The most obvious answer is to treat F as a non-inline function: when generating code for F, just like i
In the course of JavaScript learning, synchronization and Asynchronization are two very troublesome concepts, especially for beginners. In short, when two or more things happen at the same time, this is called synchronization; when they do not happen at the same time, this is called asynchronous. In the course of JavaScript learning, synchronization and Asynchronization are two very troublesome concepts, es
result of "making more money", but you cannot be absolutely certain. But if you are at the highest point of the Eiffel tower at the moment, you can give me a binary answer clearly. An example of clear business goals is that your total revenue in April this year is $5000 or more. This is something you can calculate clearly, and at the end of the month, you will be able to give the exact "yes" or "no" answer to whether you have achieved the goal. This is the clear level you need to form a goal so
time.
Int BuildNextPacket (RTCPCompoundPacket ** pack)
----- Construct the RTCP composite packet to be sent in the next pack.
Int BuildBYEPacket (RTCPCompoundPacket ** pack, const void * reason, size_t reasonlength, bool usesripossible = true)
----- Construct a BYE data packet with a reasonlength reason that gives the reason for leaving. If usesripossible is set to true, RTCP Composite data packets start with the sender report if allowed; otherwise, the RTCP Composite data packets start with th
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.