Home > Back-end >  Java instruction scheduling problems
Java instruction scheduling problems

Time:12-12

For instance=new Someobject (), is not an atomic operation, this process is divided into three steps:
1, assign the instance memory
2, Someobject constructors to initialize the member variable called
3, pointed to the instance objects allocated memory space

In the JVM instant compiler, the presence instruction reordering, in the example above, the 2 rely on 1 operation, but does not depend on 2 to 3 operation operation, that is to say, the second and the third order can't guarantee, the final execution sequence may be the 1-2-3 May be 1-2-3, so will not result in ordinary cases, get the instance is likely to be an uninitialized object references?

Don't involve multithreading, is the most common single thread instance=new Someobject () statement, can produce this kind of problem? Or am I wrong? Sincerely to solve

CodePudding user response:

Has no effect on single thread, there is no problem

CodePudding user response:

No problem

CodePudding user response:

List<> List=null;
List=new arraylist<> (a); You can first create an object to give it a null value, then where are you? Where is the new

CodePudding user response:

Single-threaded scenarios, there is no atomic operation this Monday...

CodePudding user response:

reference 4 floor HinanaiTenshi response:
single-threaded scenarios, not atomic operation this Monday...
transaction is atomic operation
  • Related