wood burning stoves
The moose likes Beginning Java and the fly likes static methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static methods" Watch "static methods" New topic

static methods

Shubh Bhat
Ranch Hand

Joined: Sep 08, 2002
Posts: 32
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

~-<br />Doing my best this time and everytime.<br />-- Me
rom chatterjee
Ranch Hand

Joined: Dec 11, 2001
Posts: 46
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 Chatterjee<BR>Sun Certified Java Programmer
I agree. Here's the link: http://aspose.com/file-tools
subject: static methods
It's not a secret anymore!