• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multi-Thread Performance

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ALl:
I wrote a Multi-Thread program to fetch web data.
and I need it run 24 hr a day. But there always
be problems:
1.It will make CPU usage up to 100%, until the
page is completely downloaded.
2.Memory is never enough, the usage keep growing
as long as the program is running, and finally
get an outOfMemory Exception.
I am using J2SE 1.4.0_01 on Windows 2000 Server.
It starts with 5 threads to get web page, 1 thread
to extract URL link in every downloaded page and
another thread to write to Database.When I stop
the Thread, the usage of memory stop growing, but
never going down unless I quit the program.
Any help will be appreciated.
Thanks.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have encountered that problem too..but it was resolved that by making my code more precise..Just look at your code that would make your thread continously make a loop, change it by sleeping the threads or using wait() and notify().
 
Ultra Powerz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks...
Yes, I have made all threads sleeping after every
page done. It can slow down the usage of CPU, but
not memory. So I still get an outOfMemory Exception if it run for a long time.
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OutofMemory error comes when all the jvm memory is consumed. Look into your code and see if there are any objects which are not been nullify.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello "Ultra Powerz",
welcome to JavaRanch!

We're a friendly group with not many rules, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name.
Thanks, and have fun!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two suggestions:
1: Make sure there are no references to the objects you no longer need. For example, if you store a reference in a container, the memory will not be released until there are no more references to a particular object.
2: Once you reset all of the references, invoke:
System.gc() or Runtime.getRuntime().gc(). This should suggest JVM to kick off a garbage collector.
 
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm responsible for several highly multithreaded applications at work.

When work arrives (batches) the apps typically spawn 20-40 threads, each of which is making HTTP (SOAP really) invocations. This happens 2-3 times in a 24 hour period.

These apps will run for *weeks* without need for a restart.

And they make no System calls to suggest garbage implementation.

I think you have a memory leak bug - just because there is a GC component in the runtime does not guarantee your code is right.

Guy
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To the 100% CPU "problem" ... why would you want a program that uses less? Would you want it to run longer than necessary? Well, maybe if you want to do anything else at the same time. I have a little download program that runs up to 100% CPU (3.1 ghz desktop PC) with about 4 threads. I gave some thought to interrupting it so I could browse the Ranch at the same time but decided to just let it have the machine for as long as it takes. Actually Windows is good enough to let me do other things, just slightly slower than usual.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you guys, starting with Kapil, are responding to a four year old thread. Let it go, eh?
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exhumition party?
Let's wait for halloween ...
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic