aspose file tools*
The moose likes Beginning Java and the fly likes Single object versus multiple Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Single object versus multiple" Watch "Single object versus multiple" New topic
Author

Single object versus multiple

Kalichar Rangantittu
Ranch Hand

Joined: Jan 15, 2002
Posts: 240
This may be obvious but still would like to know.

Please let me know if and whether there would be a performance penaltly if I had an object of class A that had a method foo() which services many many requests versus having multiple instances of the object servicing individual requests. For the discussion, lets assume that the class that represents foo() does not have any properties or problems or synchronization issues. I see that this can be made as a static method in a static class but was wondering if having a single object servicing multiple requests versus having multiple objects servicing multiple requests have any benefits one way or the other.

Thanks..


Never be satisfied with anything less than the best and you will surely pass the test...
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

If there is no synchronization, then no, it doesn't matter how many threads are accessing an object simultaneously, there will be no performance penalty, and no advantage to using multiple objects. Of course, as soon as there is synchronization, it's a different story, and then multiple server objects will perform better than one.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Single object versus multiple