Do We really need Locking for Static methods(Static Class) when the methods are heavily used by threads? Is it required when Static methods are using resources like SQL Queries/StoredProcedures ?
Thanks Pankaj
Do We really need Locking for Static methods(Static Class) when the methods are heavily used by threads? Is it required when Static methods are using resources like SQL Queries/StoredProcedures ?
Thanks Pankaj
It entirely depends on what the static methods are doing. If they're using shared resources (e.g. the same SQL connection, or modifying a shared collection) then yes, you absolutely need locking or something similar.
If, however, each method call is effectively independent, not touching any shared mutable state, the you don't need any locking.
If you have shared memory across threads (static or not) and rely on this for state information you have the potential for race conditions to occur, leading to hard to debug problems and erroneous execution.