This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

threads and static methods

 
Edward Farrow
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic