Re: concurrency, threads and objects



Tom Forsmo <spam@xxxxxxxxxx> wrote:
If I use 100
threads, I would create 100 ClassA objects, which means I would have 100
ClassA objects and 100 Thread objects.

So what ?

I don't believe in code bloat and I see it as unnecessary runtime
resource consumption. I don't subscribe to the idea that you should not
worry about resources (cpu, memory etc.), because its so cheap. The
reason is simple, bloated code runs slower and is more difficult to
maintain. Think of a program that takes up 300 MB of memory and compare
it to a program that only requires say, 150MB. The smaller program
requires less bus bandwidth between the cpu, memory and disk and less
processing cycles (barring algorithm efficiency).

You seem to see things in black and white. The world doesn't work that
way. Practically everything is an object in Java. Objects are cheap.
The entire runtime system, memory management, etc. is designed that way,
and people have put lots of effort into making it so. Anything else you
do that tries to minimize creating objects is likely to not be a
noticable improvement, and often hurts the performance of your code.

On the other hand, creating 100 threads is certainly not cheap, and
almost certainly harmful if you care about performance in this
application... unless it will be running on some kind of supercomputer
that has at least 50 processors or so. Sometimes creating 100 threads
can make your development life easier by helping you separate various
tasks in your application design; but if that cost is okay with you, you
are certainly misplacing your priorities when you worry about creating
that extra 100 objects. This isn't about whether you should be happy
with a sub-optimal program. It's about whether you should worry about
polishing the deck when the Titanic is sinking.

--
Chris Smith
.



Relevant Pages

  • Re: concurrency, threads and objects
    ... I don't subscribe to the idea that you should not worry about resources (cpu, memory etc.), because its so cheap. ... The smaller program requires less bus bandwidth between the cpu, memory and disk and less processing cycles. ... I have numerous times created applications that require a fraction of memory or cpu power compared to a someone's idea that you should not worry about it. ... In some cases I have also created working and stable solutions when others have not managed to get one off the ground, because of code bloat. ...
    (comp.lang.java.programmer)
  • Re: Computer advice please?
    ... Don't worry about speed they are ... about 4x the battery life - which I head you ask for. ... Don't worry about video memory unless you are gaming. ...
    (alt.gathering.rainbow)
  • Re: Structure of large link libraries in f95
    ... Won't memory use and build time be about the same? ... it would save some disk space. ... Again, don't worry ... worry about large statically-sized data arrays - which are typically set ...
    (comp.lang.fortran)
  • [Full-Disclosure] ALERT ALERT plaintext passwords in linux ALERT ALERT
    ... > Don't worry, it does not actually occupy your computer's resources, except some memory. ... sometimes a kernel rootkit will hijack the stat syscall.. ...
    (Full-Disclosure)
  • Re: OSX vs XP
    ... > There is either swapping or a waste of RAM. ... > is loaded faster than data that hasn't been in memory before at all. ... We wouldn't need GB of RAM in systems if people didn't think ... Fortunately it's cheap. ...
    (comp.sys.mac.advocacy)