Suppose I have the following code snippet
public synchronized void method() { if(something == null) { something = new SomeThing(); } //do something }
Now suppose that in a multi-threaded environment, one thread [Thread 1] enters a method and was unloaded right after its execution new Something();, but before it could assign it something. Then another thread [Thread 2] also tries to call the method. What exactly is happening now? What happens to the lock Thread 1 acquired? Will Rollback Thread 1 Steps?
new Something();
something
Thread1 , . Thread2 , , BLOCKED. , Thread1, . Thread2.
BLOCKED
2 , 1 , .
Thread 1, Thread 1 Something() . Thread 2 Something().
, Thread 1 , . Thread 1 , (), Thread 2 .
Source: https://habr.com/ru/post/1791638/More articles:Margin error, upper margin goes at the top of the lower margin - cssThe modern equivalent of LLVM AnnotationManager? - llvmHow can I handle paid memberships safely? - djangoASP.NET Web Form Render Engine displays control tree? Finding Information About Rendering Logic - asp.netMargin does not press another margin - cssWhat are the options for using temporary tables in SQL database systems? - sqlPython search technology: word similarity - pythonзакрыть все сокеты после использования? на стороне сервера - javaList Generation Erlang - listPerl Linux :: Inotify2 - can no longer respond to events - eventsAll Articles