The lack of synchronized methods in Java

What are the disadvantages of having a large non-static Java method synchronized? A great method in the sense that it takes 1 to 2 minutes to complete the execution.

+3
source share
6 answers

If you synchronize a method and try to call it twice at the same time, one thread will have to wait two minutes.

Actually, this is not a question of "flaws." Synchronization is necessary or not, depending on what this method does.

If it is critical that the code runs only once at the same time, you need synchronization.

, , Semaphore, (, ).

, JVM. JVM , . () .

+17

, , , , , , , . , , 2 - , ( ), . . (, , , , , .)

+4

, , , .

, ( , , ), , . , , , ( , , synchronize, ).

java.util.concurrent .

+2

, , 1-2 . , .

, , , , ... .

+1

Java:

0

Java:

 1. Increase the waiting time of the thread
 2. Create a performance problem
0

Source: https://habr.com/ru/post/1716649/


All Articles