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