File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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


Rom Chatterjee<BR>Sun Certified Java Programmer
 
wood burning stoves
 
subject: static methods
 
Similar Threads
static variables and methods
When do I need to be concerned with threading?
Are these two methods equivalent?
Refactoring a static method for use in a clustered environment(multiple threads)
static method