Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static methods

 
Shubh Bhat
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I understand about static method is: we don't have to instantiate an object of a class (where the static method is) to call the static method.
But I have a lot of questions regarding it.
how are static methods handled in a multithreaded application?
I have a class ABC with a static method public static stat(ArrayList a). now assume there are more threads calling at the same time ABC.stat(a). What happens? have some threads to wait until the others have finished calling the method, or can static methods be multithreaded, (can they perform simultaniously)?
What really happens behind the sceen? I mean what happens in the memory level and so on.
If there is a good link where I can read some more things about static methods please post it as a reply, I would be more than happy to read it
 
rom chatterjee
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply, many threads can access the method at once. This could be bad, depending on what the method does. If you want a section of code to be accessed by one thread at a time then use the synchronised keyword.
This means that a thread will get a lock on the piece of code prior to entering the code block and wont relinquish it until it exits. Any threads wanting to use the same code block will have to wait until it is free. There is no guarantuee which of your waiting threads will get the lock next.
You can try seeting the priority of htreads to circumvent this, but thats getting a bit more advanced...
Hope this helps
Rom
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic