If we have thread safe data structure lets say StringBuffer. Methods of StringBuffer are syncronized what does this mean if we have multithreaded method (async) ? Does it lock the resourse when it's using it and acts like a sync process in multithread environment? In other words we have async method, but because of structures it acts like sync right?
Asked
Active
Viewed 38 times
0
-
1See Oracle's [The Java Tutorials: Synchronized Methods](https://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html) – Andy Thomas Mar 11 '20 at 21:42
-
1Say you have a number of threads sharing a StringBuffer and appending strings to it. StringBuffer would allow different threads to add strings to it concurrently. individual strings being added would be preserved intact (not overwritten partly or having bits lost, for instance). The order in which the strings would be added would be indeterminate. StringBuffer is pretty useless. Definitely read the linked tutorial. – Nathan Hughes Mar 11 '20 at 21:45