java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
In the Handler.java class im creating another thread , and invoking that thread with start() method.
I came across on the internet that,calling run() is a better way ,it might help resolving out of memory error.
Please let me know what might be the other reason (if any) and how can i come across this exception.
real time benifits of using run() over start() method.
Also, the error (OutOfMemoryError) is more about resource management. How many Threads are you creating? How much memory per Thread? It sounds more like you have to find out why you are running out of memory, not find a better way of starting new Threads (though the two may be linked).
Joined: May 20, 2008
Thanks for the reply,
Its a tracking application,so when i get the GPRS string i would insert the data through a thread.So the number of threads encounter would be in thousands.I'm using netbeans 6.1 .Thought to look out for the heap dump unfortunately the dump is so huge i can not even have look at it.
Kindly give me some suggestions,that how can i use the threads to work effectively and get out of OutOfMemory exception.
Working with thousands of Threads is a bad idea. Why do you need thousands of threads? What is the task they are running? More importantly, how long are those tasks supposed to take?
You need to limit the total resource consumption of your application, or provide more resources. One way is to limit the total number of Threads that can be active at one time. You might be able to run a Thread pool of some reasonable size, then when new tasks come in put the task into a queue that the Thread pool executes. If your Thread Pool is busy (too many tasks) you can either reject the request or put it in line to wait for the next available Thread. Look up the ExecutorServices and Java Concurrency tutorial to see how to do this. How useful this approach is depends entirely on what the tasks do and how long they live.