Your code creates 1000 threads. It is extremely expensive, requiring more than 1 GB of memory.
And then all these threads compete for one lock, essentially serializing (de-threading) the whole operation.
But your castle is working fine, there is nothing to worry about. Itβs just that when you run this application it may seem like your computer is crashing.
Also note that the object you are trying to protect must be bound 1 to 1 with the locker object.
, , , .