문제

Assume I have a class with two methods method1 and method2. I have made both of these methods synchronized. Assume a class calls method1 and the same time a different class calls method2. Will both these methods execute at the same time?

도움이 되었습니까?

해결책

Two threads can run two different methods at the same time. If you use synchronized it can limit the threads from running the two method at the same time, if you lock the same object. However, if your two method synchronize on different objects, they can still be as concurrent.

다른 팁

when you set a syncronized method only one process can use that method at time, this is normally used for concurrence scenarios, the execution of your two differents methods will be executed depending on the process execution in background, so syncronized its only for restrict that two threads execute the same method at the same time. Regards

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top