Out of memory.

Does anyone know what could cause the following exception? I get this exception as soon as I run my application. I am using JRE 1.5.0_8. The problem is, some times I get this exception and some times not.

Exception in thread"Thread-52445" java.lang.OutOfMemoryError: Java heap space

Exception in thread"Thread-52452" java.lang.OutOfMemoryError: Java heap space

Exception in thread"Thread-52457" java.lang.OutOfMemoryError: Java heap space

Exception in thread"Thread-52459" java.lang.OutOfMemoryError: Java heap space

Exception in thread"Thread-52488" java.lang.OutOfMemoryError: Java heap space

Exception in thread"Thread-52499" java.lang.OutOfMemoryError: Java heap space

Exception in thread"Thread-52586" java.lang.OutOfMemoryError: Java heap space

[981 byte] By [BinaryDecimala] at [2007-11-27 8:09:20]
# 1
> Does anyone know what could cause the following exception?Yes. You've run out of heap space. Your program is doing something which consumes a lot of memory.
quittea at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 2
I can add to this an experience I once encountered. I noticed once my VM increasing a lot but the physical memory stayed the same. Any idea? I know the question is too broad, but I am trying myself to narrow it down.Thanks,
BinaryDecimala at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 3
Get a profiler and watch the memory usage. That'll tell you what's eating it up.
hunter9000a at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 4
Can you at least give a hint on what kind of work your application is doing?
quittea at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 5
The other problem is I can't reproduce it easily. I am thinking my Java is going out of sync of some sort and losing it track of heap usage.
BinaryDecimala at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 6
> The other problem is I can't reproduce it easily. I> am thinking my Java is going out of sync of some sort> and losing it track of heap usage.Is this more likely than you having a bug?
sabre150a at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 7
It抯 mostly GUI. I have a bunch of threads that run at the beginning and continue running until the GUI is ready to use by the user.
BinaryDecimala at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 8

> The other problem is I can't reproduce it easily. I

> am thinking my Java is going out of sync of some sort

> and losing it track of heap usage.

Then you need to focus on being able to reproduce the problem. Until you know what triggers the memory leak, you can't fix it. It's almost certainly a bug in your code, not a bug in the vm.

hunter9000a at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 9
Possible. But hard to find since I can't reproduce it.
BinaryDecimala at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 10

It could be caused by so many different things. Unless you want a very generic answer, we need more information.

The generic answer would be that the JVM has ran out of allocated memory. What caused it we cannot tell by just the exception.

You might be able to control it by using the -Xmx parameter at the command line when you run it, but my guess is that your code is doing something so that doing this won't help any. I'm guessing that there is some kind of loop where it is creating objects or recurssive calls where it is using up all available memory and that no matter what value you use it will continue to use up all available memory.

llemonsa at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 11
> It抯 mostly GUI. I have a bunch of threads that run> at the beginning and continue running until the GUI> is ready to use by the user.How does this structure result in Java 'going out of sync' ?
sabre150a at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 12
I do have a profiler but without reproducing, it is useless. Could this happen, if one closes the application and restarts it very quickly. Would the JVM in this case have a problem?
BinaryDecimala at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 13

> I'm guessing that there

> is some kind of loop where it is creating objects or

> recurssive calls where it is using up all available

> memory and that no matter what value you use it will

> continue to use up all available memory.

I agree that increasing the memory won't solve the problem if there is a memory leakage. The memory leakage is however probably not related to a recursive loop since you usually get a StackOverflowError before you get an OutOfMemoryError.

kajbja at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 14
> I do have a profiler but without reproducing, it is> useless. Could this happen, if one closes the> application and restarts it very quickly. Would the> JVM in this case have a problem?No
kajbja at 2007-7-12 19:52:18 > top of Java-index,Java Essentials,Java Programming...
# 15
In normal cases the application consumes up to 67M at start up and I do have as you said a -Xmx of 300M.
BinaryDecimala at 2007-7-21 22:30:33 > top of Java-index,Java Essentials,Java Programming...
# 16
> In normal cases the application consumes up to 67M at> start up and I do have as you said a -Xmx of 300M.Do you manipulate large images?
kajbja at 2007-7-21 22:30:33 > top of Java-index,Java Essentials,Java Programming...
# 17
No.Jjust small icons which end up darwing a structure of hard ware.
BinaryDecimala at 2007-7-21 22:30:33 > top of Java-index,Java Essentials,Java Programming...
# 18
I'd start by looking into what creates the threads. From what little you posted, I would guess that your app is creating well over 50,000 threads, which is a lot of threads for any app. and could consume a lot of memory depending upon how large each object is.
llemonsa at 2007-7-21 22:30:33 > top of Java-index,Java Essentials,Java Programming...
# 19
This is what I don't understand. I don't have that much of threads. Probably I have up to 10 threads runing at the same time at start up.
BinaryDecimala at 2007-7-21 22:30:33 > top of Java-index,Java Essentials,Java Programming...
# 20
Maybe you're swallowing an exception and thus walk into an infinite loop where you create more and more threads ...?
quittea at 2007-7-21 22:30:33 > top of Java-index,Java Essentials,Java Programming...
# 21
Going back to the heap size, as far as I understand when the heap increases the RAM will increase. Is this correct?
BinaryDecimala at 2007-7-21 22:30:34 > top of Java-index,Java Essentials,Java Programming...
# 22

Ok. In your original post a line says:

Exception in thread "Thread-52445" java.lang.OutOfMemoryError: Java heap space

Any idea to what the "Thread-52445" refers? Is it a name of a thread? Do you name your threads according to the number in which they were created?

llemonsa at 2007-7-21 22:30:34 > top of Java-index,Java Essentials,Java Programming...
# 23
Very possible cause. I will have to double check to see if I have this situation.
BinaryDecimala at 2007-7-21 22:30:34 > top of Java-index,Java Essentials,Java Programming...
# 24
Available RAM to the app., yes. But, if you have some kind of infinite loop that is creating objects it will consume all the "RAM" you give it.
llemonsa at 2007-7-21 22:30:34 > top of Java-index,Java Essentials,Java Programming...
# 25

>Ok. In your original post a line says:

>Exception in thread "Thread-52445" java.lang.OutOfMemoryError: Java >heap space

>Any idea to what the "Thread-52445" refers? Is it a name of a thread? >Do you name your threads according to the number in which they >were created?

No, I have no idea. I don't name my threads. If I name them though, would java print the exception with correct names or would it print the threads IDs?

BinaryDecimala at 2007-7-21 22:30:34 > top of Java-index,Java Essentials,Java Programming...
# 26

>Available RAM to the app., yes. But, if you have some kind of infinite >loop that is creating objects it will consume all the "RAM" you give it.

I once noticed an exception very similar to this but in That one I was able to see what happened to the memory. I had the application at -Xmx300M and when started the RAM for this application was at 68M, which is normal but its VM size increase like crazy to over than 300M, which is above the requested size, and it crashed. Put in mind I have 3G of RAM on my machine when it happened.

Thanks,

BinaryDecimala at 2007-7-21 22:30:34 > top of Java-index,Java Essentials,Java Programming...
# 27
I would just like to add that my application does talk to hardware via serial port and TCP.
BinaryDecimala at 2007-7-21 22:30:34 > top of Java-index,Java Essentials,Java Programming...
# 28

If you haven't already, try increasing the heap by using the java command option -Xmxnm, where n is the heap in MB. Assuming you are using Win 32 XP, you'll find that your maximum value will be somewhere between 1200MB and 1700MB (approx.) This is a limitation of Windows, not much can be done to change it.

You can use this command with varying values of MB to find your maximum:

java -Xmx1330m -version

girraj_meenaa at 2007-7-21 22:30:34 > top of Java-index,Java Essentials,Java Programming...
# 29

Here is another pattern of exceptions which I got before it crashed.

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15121" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15126" java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15205" java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15222" java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15283" java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-8" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15304" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15392" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15422" java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

Exception in thread "Thread-14406" Exception in thread "Thread-76" Exception in thread "Thread-15425" java.lang.OutOfMemoryError: Java heap space

java.lang.OutOfMemoryError: Java heap space

java.lang.OutOfMemoryError: Java heap space

java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15424" java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15177" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15210" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15312" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-14573" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15430" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-156" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15434" java.lang.OutOfMemoryError: Java heap space

Exception occurred during event dispatching:

Exception in processing network message message.Connect

Exception in thread "Thread-77" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-14110" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15454" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15442" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15452" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15418" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15449" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-14268" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-14505" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-14474" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-14681" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-14599" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-15457" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-14436" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-14694" java.lang.OutOfMemoryError: Java heap space

BinaryDecimala at 2007-7-21 22:30:34 > top of Java-index,Java Essentials,Java Programming...
# 30

>If you haven't already, try increasing the heap by using the java >command option -Xmxnm, where n is the heap in MB. Assuming you >are using Win 32 XP, you'll find that your maximum value will be >somewhere between 1200MB and 1700MB (approx.) This is a >limitation of Windows, not much can be done to change it.

>You can use this command with varying values of MB to find your >maximum:

>java -Xmx1330m -version

The machine where the application will run has 512M. What happens if I put my request (-Xmx) at a value greater than 512M?

BinaryDecimala at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 31

I just did a little test, and the default name for the thread is "Thread-n" where n is the number of the thread that was created, so from the looks of it, you have over 50k threads in your original post, and in this one, there are over 15k threads.

What I would do is some old-fashioned debugging and put in some System.out.println()'s in the location where the threads are being created, or some logger.info()'s, if you are using logging. I would also put in a lot of System.out.println()'s in several other key locations with whatever information that would help you figure out from where that print is being printed, and what is happening at that location.

llemonsa at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 32
Would n be the number of threads alive or the number of threads that have been created so far including the ones stopped and collected by the GC?
BinaryDecimala at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 33

Suppose you had 6 threads called Thread-1, Thread-2, and so on up to Thread-6 in the JVM that you designed. Then Thread-2 terminates. What do you do, as a sensible JVM designer? Do you rename Thread-3, Thread-4, and so on? Or do you just leave them alone, suspecting that people might get confused if you changed their names?

A lot of questions can be answered by thinking about what somebody with some common sense would do.

DrClapa at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 34

I believe that it is the number of threads that were created. Whether they are all still alive or not may not matter. I don't know for certain without doing a test first, but that is my guess.

If you are creating 10 threads, killing those 10 threads and creating 10 more, etc. 5,000 times, your GC might not have a chance to collect all the garbage and you could still run out of memory, but from the looks of your error message, there might be more than just 10 live threads at any one time.

llemonsa at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 35
Thank you everyone for your help.
BinaryDecimala at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 36
I did confirm my guess. The thread number is the number of threads that were created whether or not any of them were killed previously or not.
llemonsa at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 37
> Thank you everyone for your help.My pleasure.
llemonsa at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 38

>Suppose you had 6 threads called Thread-1, Thread-2, and so on up >to Thread-6 in the JVM that you designed. Then Thread-2 terminates. >What do you do, as a sensible JVM designer? Do you rename Thread->3, Thread-4, and so on? Or do you just leave them alone, suspecting >that people might get confused if you changed their names?

>A lot of questions can be answered by thinking about what somebody >with some common sense would do.

Just a curious question for you. Are you in theory filed or practice field?

BinaryDecimala at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 39

> If you are creating 10 threads, killing those 10

> threads and creating 10 more, etc. 5,000 times, your

> GC might not have a chance to collect all the garbage

> and you could still run out of memory,

Are you talking about objects (e.g., threads) that are eligible for GC, but haven't actually been GCed yet, and therefore you could run out of memory?

No, that cannot happen. When you try to allocate memory, if there's not enough available, GC will run before OutOfMemoryError is thrown.

jverda at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 40
I am in a practiced field. A Software Engineer.
llemonsa at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 41

I believe that depends upon the JVM. I have seen some poorly written JVM's that have ran out of memory and shut down. I had to code around it.

> > If you are creating 10 threads, killing those 10

> > threads and creating 10 more, etc. 5,000 times,

> your

> > GC might not have a chance to collect all the

> garbage

> > and you could still run out of memory,

>

> Are you talking about objects (e.g., threads) that

> are eligible for GC, but haven't actually been GCed

> yet, and therefore you could run out of memory?

>

> No, that cannot happen. When you try to allocate

> memory, if there's not enough available, GC will run

> before OutOfMemoryError is thrown.

Message was edited by:

llemons

llemonsa at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 42
Oh Thanks llemons, but I meant to ask DrClap.
BinaryDecimala at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 43

> I believe that depends upon the JVM. I have seen

> some poorly written JVM's that have ran out of memory

> and shut down. I had to code around it.

I don't believe that. You probably had a bug and altered the code so that you removed the bug or just made it harder to expose the bug.

Kaj

kajbja at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 44
I didn't actually change the code. I had to increase the memory heap large enough so that it wouldn't run out of memory before the GC was able to clear the memory. It still didn't solve all the problems, but unless the server was being hit extremely hard it, was alright after this.
llemonsa at 2007-7-21 22:30:39 > top of Java-index,Java Essentials,Java Programming...
# 45

> I didn't actually change the code. I had to increase

> the memory heap large enough so that it wouldn't run

> out of memory before the GC was able to clear the

> memory. It still didn't solve all the problems, but

> unless the server was being hit extremely hard it,

> was alright after this.

Then it wasn't a bug in the GC. The VM will do a full gc and throw an out of memory error if it still isn't able to find enough free memory to allocate/reserve for the object that you are trying to create.

kajbja at 2007-7-21 22:30:44 > top of Java-index,Java Essentials,Java Programming...
# 46

I've seen suns vm's core dump due to excessive thread creation. I think it is becuase, on many OS's there is a 1-1 relationship between java threads and OS threads/processes. OS level threads/processes are created with thier own stack (i.e. take up memory) that is not in the java heap. If your java heap is taking most of the available address space and then you create lots of threads you can blow the available address space and no longer create any new threads. This seems to cause the vm to exit unceremoniously.

The solution to the problem was to REDUCE the amount of memory that could be used as java heap. This gave enough free address space to handle thread creation.

matfud

matfuda at 2007-7-21 22:30:44 > top of Java-index,Java Essentials,Java Programming...
# 47
The way I debugged it to find out what happened was to put a sleep and it never occured, but I didn't want the pauses so since the adding memory worked, they decided to go that route.This was NOT Sun's JVM, by the way. It was some JVM we were being forced to use.
llemonsa at 2007-7-21 22:30:44 > top of Java-index,Java Essentials,Java Programming...
# 48

I've seen suns vm's core dump due to excessive thread creation. I think it is becuase, on many OS's there is a 1-1 relationship between java >threads and OS threads/processes. OS level threads/processes are >created with thier own stack (i.e. take up memory) that is not in the >java heap. If your java heap is taking most of the available address >space and then you create lots of threads you can blow the available >address space and no longer create any new threads. This seems to >cause the vm to exit unceremoniously.

>The solution to the problem was to REDUCE the amount of memory >that could be used as java heap. This gave enough free address >space to handle thread creation.

>matfud

So, you mean I should reduce the -Xmx value? Do you think adding more JVM arguments would help? Like -Xms or -XX:MaxHeapFreeRatio or etc...

BinaryDecimala at 2007-7-21 22:30:44 > top of Java-index,Java Essentials,Java Programming...
# 49
I don't believe any JVM arbuments will help until you find how/why so many threads are being created.
llemonsa at 2007-7-21 22:30:44 > top of Java-index,Java Essentials,Java Programming...
# 50

> I've seen suns vm's core dump due to excessive thread

> creation. I think it is becuase, on many OS's there

> is a 1-1 relationship between java >threads and OS

> threads/processes. OS level threads/processes are

> >created with thier own stack (i.e. take up memory)

> that is not in the >java heap. If your java heap is

> taking most of the available address >space and then

> you create lots of threads you can blow the available

> >address space and no longer create any new threads.

> This seems to >cause the vm to exit unceremoniously.

>

>

> >The solution to the problem was to REDUCE the amount

> of memory >that could be used as java heap. This gave

> enough free address >space to handle thread

> creation.

>

> >matfud

>

> So, you mean I should reduce the -Xmx value? Do you

> think adding more JVM arguments would help? Like -Xms

> or -XX:MaxHeapFreeRatio or etc...

No, not in your case. I was just commenting about an odd situation that can occur (and has for one of our customers).

Why on earth are you creating so many threads? Have you followed the earlier suggestion of finding all "new Thread" instances and putting debug logging (even System.err.out) before them? At least that way you will know how many threads you are creating.

It sounds like you may have, inside your code, a recursive call that ocasionally occurs which creates new threads. This could cause the OOME before a StackOverflow occurs.

matfud

matfuda at 2007-7-21 22:30:44 > top of Java-index,Java Essentials,Java Programming...
# 51

> I don't believe any JVM arbuments will help until you

> find how/why so many threads are being created.

It's not important unless many of them still are alive.

@Op. Create a thread dump and see how many live threads you have.

You can also try to reduce the java thread stack size if you have lots of threads (-Xss)

Kaj

kajbja at 2007-7-21 22:30:44 > top of Java-index,Java Essentials,Java Programming...
# 52
I am not able to reproduce the bug until now. In normal cases using a profiler to check all kind of threads I have for starting up the GUI, loading a database, communicating with hardware and what not is up to 30 threads.
BinaryDecimala at 2007-7-21 22:30:44 > top of Java-index,Java Essentials,Java Programming...
# 53

my suggestions are

1. print exit value of all loops

2. print messages on all object creation and destruction, specially your own classes

3. get your program verified by some other friend who have no prior knowledge of your code

From my experience i can tell that in your program some loop is creating classes and the loop is not exiting. Also the cause that it is happening sometimes and sometimes not is because the loop may not be triggering every time, that is it is triggered by some action handler.

regards

i_virus

i_virusa at 2007-7-21 22:30:44 > top of Java-index,Java Essentials,Java Programming...
# 54

Every time you create a thread or object, do a System.out.println(object); where object is the new object you created. Somewhere there is a loop that is creating a lot more threads than you think should be created. If it is in a GUI, then in the listener you probably are creating object(s) and only think that listener is only getting called once when in fact it may be being called hundreds or even thousands of times for each click or even mouse-over.

Without being able to see what you are doing with listeners it is almost impossible to tell.

llemonsa at 2007-7-21 22:30:44 > top of Java-index,Java Essentials,Java Programming...
# 55

> I am not able to reproduce the bug until now. In

> normal cases using a profiler to check all kind of

> threads I have for starting up the GUI, loading a

> database, communicating with hardware and what not is

> up to 30 threads.

You don't need a profiler to create a thread dump. You can create a thread dump from a running application if you are launching it from a console (windows) or if you are using unix/linux.

Kaj

kajbja at 2007-7-21 22:30:44 > top of Java-index,Java Essentials,Java Programming...