Two Laptop Bag*
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 Android Security Essentials Live Lessons this week in the Android 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
 
Similar Threads
populate a form
Dead Thread !!
Static method local variables
Can static methods cause any kind of overhead?
Sign soap header with handler in WebSphere 6.1