|
![]() |
Stephan van Hulst wrote:Synchronization only has an effect when two different threads access pieces of code protected by the same object.
...
Stephan van Hulst wrote:Welcome to CodeRanch!
The use of the synchronized keyword in your example is pointless. The piece of code that is being synchronized is only ever executed by a single thread, and no other thread synchronizes on the manager object.
Synchronization only has an effect when two different threads access pieces of code protected by the same object.
Kieu Thoai wrote:Thank you for answer , it very helpfull
One more question when i used service = Executors.newFixedThreadPool(20); -> has it will create 20 threads at the same time
But when i used syncrhonized as above it creates them one by one right ?
Good night. Drive safely. Here's a tiny ad for the road:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|