Static method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jyohere
    New Member
    • Apr 2007
    • 73

    Static method

    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
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by jyohere
    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
    I'd like to hear your thoughts about it first.

    Comment

    • jyohere
      New Member
      • Apr 2007
      • 73

      #3
      Originally posted by r035198x
      I'd like to hear your thoughts about it first.
      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 stupid

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by jyohere
        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 stupid
        No 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

        • jyohere
          New Member
          • Apr 2007
          • 73

          #5
          Originally posted by r035198x
          No 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?
          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....

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by jyohere
            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....
            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 ....

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              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

              • jyohere
                New Member
                • Apr 2007
                • 73

                #8
                Originally posted by JosAH
                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.
                wat if two threads call the same static method

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by jyohere
                  wat if two threads call the same static method
                  You just wrote that there are no two (or more) threads, so that is a hypothetical
                  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,

                  Jos

                  Comment

                  Working...