I have a doubt.
Suppose in a multithreaded environment 10K users are using a site simultaniously and the site has a static method.
If a static method in JAVA creates a single instance, then the 10k-th user needs to wait for the method until rest of the users complete their usage.
Am I right?
Can anybody please explain?
解决方案
If a static method in JAVA create a single instance, then 10K th user need to wait for the method untill rest of the usres complete there usage.
Calling a static method doesn't create an instance implicitly. You can do so within the method, of course - but you don't have to.
Nor does creating an instance require a lock - although again, you can add synchronization should you wish to.
So in the case of a simple static method which doesn't need any synchronized access to shared data, there should be no problem with multiple threads calling that method concurrently.