educative.io

Printing Foo Bar n Times - Alternative solution

Hi,

I was wondering why we were using synchronized block to solve this problem, but then for the next one (which is very similar, right?), we take a Semaphore approach? Would both approach work for each exercice or is there a particular reason we are using different ones in those cases?

Thanks

@Tisserand
Hi,
synchronized block is a low-level synchronization that can be applied to trivial problems like printing Foo Bar n time but when the problem starts getting complex then these low-level synchronizations won’t be able to help you achieve what you want. In such cases, the high-level synchronization (Semaphore) steps in and helps you to solve your problem.