what happens when a static method(which uses static variables) is called by two instances of an object simultaneously. ..will the method execution be slower
Static method
Collapse
X
-
am not sure....actuall y i used it in my project.....wat i meant was that when one instance call to the static method is executing another call to that same method comes from another instance....the process becomes really slow....am i clear or sound stupidOriginally posted by r035198xI'd like to hear your thoughts about it first.Comment
-
No your question doesn't sound stupid (not to me anyway).Originally posted by jyoheream not sure....actuall y i used it in my project.....wat i meant was that when one instance call to the static method is executing another call to that same method comes from another instance....the process becomes really slow....am i clear or sound stupid
I just wanted to hear your explanation first. Just to be sure, your application uses multithreading?Comment
-
no, it does not use multithreading. ...actually i create an object....it calls an instance method and this instance method calls a static method which uses static variables....an d this is repeated for say one more object.....ie. when the static method called by the previous object is executing....Originally posted by r035198xNo your question doesn't sound stupid (not to me anyway).
I just wanted to hear your explanation first. Just to be sure, your application uses multithreading?Comment
-
Well then it doesn't happen like that. When you call the static method for the first time control passes to that method and the next steps are done only after that first method call has completed. Remember there's only one thread executing all the statements so unless you create some threads yourself ....Originally posted by jyohereno, it does not use multithreading. ...actually i create an object....it calls an instance method and this instance method calls a static method which uses static variables....an d this is repeated for say one more object.....ie. when the static method called by the previous object is executing....Comment
-
AAMOF, a static method call should be a bit faster than a (virtual) non-static
method call. The address of the static method is resolved during class loading
(equivalent to the ordinary static linking process), while a dynamically linked
(virtual) method call takes *two* memory fetches. Of course this takes next
to nothing timewise speaking.
kind regards,
Jos
ps. without seeing the actual methods noone can explain why things get slow.Comment
-
wat if two threads call the same static methodOriginally posted by JosAHAAMOF, a static method call should be a bit faster than a (virtual) non-static
method call. The address of the static method is resolved during class loading
(equivalent to the ordinary static linking process), while a dynamically linked
(virtual) method call takes *two* memory fetches. Of course this takes next
to nothing timewise speaking.
kind regards,
Jos
ps. without seeing the actual methods noone can explain why things get slow.Comment
-
You just wrote that there are no two (or more) threads, so that is a hypotheticalOriginally posted by jyoherewat if two threads call the same static method
question. When multi-threading rears its ugly head you have to synchronize
certain blocks of code. I can't tell you anything more without knowing what
you're trying to design/implement.
kind regards,
JosComment
Comment