This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes threads and static methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "threads and static methods" Watch "threads and static methods" New topic
Author

threads and static methods

Edward Farrow
Ranch Hand

Joined: Apr 02, 2002
Posts: 32
class RequestProcessor
{
public static void handleRequest(Request r)
{
//perform operations on r using variables local to handleRequest method
}
}
if i had multiple threads each with their own Request object calling RequestProcessor.handleRequest(request) simultaneously would there be threading issues or threads conflicting? Would there be any benefit making handleRequest a synchronized method?
Ratna Singh
Greenhorn

Joined: Mar 17, 2002
Posts: 19
Originally posted by Edward Farrow:
class RequestProcessor
{
public static void handleRequest(Request r)
{
//perform operations on r using variables local to handleRequest method
}
}
if i had multiple threads each with their own Request object calling RequestProcessor.handleRequest(request) simultaneously would there be threading issues or threads conflicting? Would there be any benefit making handleRequest a synchronized method?

Hi, I think if the data and objects in a method are part of the thread context you wouldn't need to use mutual exclusion or locks. In this case request is thread specific so you shouldn't have to. However you could synchronize on objects within methods that are global (visible to other threads) and problems of concurrancy exist, ie only one thread should be allowed to excecute the critical section on these objects at one time.
Ratna.
 
 
subject: threads and static methods