• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

threads and static methods  RSS feed

 
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?
 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!