Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Download and Multithread  RSS feed

 
Gia Phuong Tran
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am coding a download program, I use multithread in this program.
But It has an error ocurred:
It is : OutOfMemory, can not create a new native thread.
I have found solutions:
-increase heap memory size
-reduce max thread using in program.

I have a question :
How the way : JVM control and allocate threads ?

Thanks and best regard.
phuongtg
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

I'd focus on figuring out what's causing the error before I blindly hand out more memory. Out of memory errors are often caused by recursion that never exits. Any chance that's what you are seeing? What does your stack trace look like?

Or are you trying to store gigantic downloads in memory? It might be better to read a manageable buffer into memory and write it to disk, then read another chunk into the same buffer.

How many threads are you talking about? Do they all run at once or do you create and run and destroy a lot of them?

Show us a small bit of your download code so we can see what's going on.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One important point is, though, that despite the error message, this really has nothing to do with threads, any more than not being able to fit into your pants is a problem with pants. In both cases, the problem is excessive consumption.

Because this is really not thread-related, I'll move it to Java in General (Intermediate).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!