Forums Register Login
Download and Multithread
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.
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.
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).

This thread has been viewed 383 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 22, 2018 14:44:47.