So basically what will happen if you have the following:
class SyncTest { private final static List<Object> mObjectList = new ArrayList<Object>(); public synchronized void mySyncMethod(Object object) { new Thread(new Runnable() { public void run() { synchronized (SyncTest.this) { for (int i = 0; i < mObjectList.size(); i++) { //Do something with object } } } }).start(); } }
. - ( ). , , . , , , , . , .
, mySyncMethod, SyncTest, , , .
, , SyncTest, , . SyncTest - ( , , mySyncMethod SyncTest, , mySyncMethod SyncTest), , . , , , .
:
, , , , , .
SyncTest , , , .
, SyncTest; , , , , .
, , .
synchronized Thread, synchronized for.
synchronized
Thread
for
, , , , , this . , SyncTest.this, SyncTest. mObjectList.
this
SyncTest.this
SyncTest
mObjectList
this , Thread , mySyncMethod .
mySyncMethod
, , Concurrent, List concurrency.
Concurrent
List
, synchronization , , , - .
synchronization
mySyncMethod() , , , SyncTest.
, synchronize , THAT SyncTest.
( , 'this' , )
, . .
Source: https://habr.com/ru/post/1540743/More articles:Postgres returns records in the wrong order - indexingElixir: how to make a structure enumerable - structIs it possible to configure Crashlytics on iOS without installing the application on each developer's workstation? - iosOsgi eclipse: how to export a package from a package of fragments and make them visible to an external package? - javaiOS Aspect Fill Image Resizing with content matching left / top - iosIntersection of two range arrays - arraysPlanning a Zend Capture and Viewing Content as a Variable - viewHow to write a consumer who counts how many times he has been called? - javahow to run telnet php - phpHow to save cookies with the Chrome Hosted App web browser - google-chrome-appAll Articles