Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Objects in a multi threaded environment. Code segments?  RSS feed

 
Suneet Kamath
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a class is instantiated by multiple threads does each object of the class share the space of the methods or the class body.
What I am trying to find out is whether there exists a "code segment" for each of these objects or one that is common for all.
The problem I am trying to highlight to a co-worker is that a 5000 line class file (say x) being called by multiple intances of multiple servlets may not be the optimal way to design the system. Will each servlet instance have a one chunky object of x.
The class x can be broken up into multiple classes since the functionality for each servlet in the class is different. I feel that this is more efficient as well as well as more organized.
The argument offered is that the "code segment" of the 5000 line file is the same for all objects, but the "data segment" is different for each. Therefore it is justified !
I haven't come across the term "Code segment" (in program memory) with reference to the Java language till date and would be grateful if someone could enlighten me in this particular area.
I can probably prove or disprove this by memory profiling but I want a theoretical solution to this issue with a reference link if possible.
[ December 09, 2002: Message edited by: Suneet Kamath ]
[ December 09, 2002: Message edited by: Suneet Kamath ]
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suneet
I agree with you on this

but the "data segment" is different for each.

By breaking up a single class into multiple class does not mean that you are going to have reduced memory. You still will have the same amount of data stored in one or in multiple classes.
 
gautham kasinath
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, about breaking it up into smaller classes and accessing them..
well that depends on how you design the class.
On the facet it looks as if, when this big class was done, a lot of brainstorming was done to decide on its responsibilities.
But then now that you want to re-define the CRC ( read as classes, responsibility and collaboration ) it is wise to have all the common data put in one data class/object and have it as a singleton, static.
That would save you the data segment cost, since you shant have to have a redundancy in the data.
But as far as the code segment goes, you need to dig deeper into JVM and find out how the execution of the lines of code is going to be, and what would be the best way to implement it.
Ofcourse, the profiler would be a good idea to start with on the collaboration design.
Lupo
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!