×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

java.lang.outOfMemoryError

Java program, unlike C program will swap to virtual memory if out of
physical memory. Java only allocate a block of physical memory for
JVM to run application.

I have a servlet that will receive pretty heavy http request. There
will be a chance of OutOfMemory Error if it receives too many request
at a time.

Any good way I can prevent OutOfMemoryError to happen? Since If the
JVM throws an OutOfMemroyError, that means JVM is crashed and it will
no longer function correctly until I restart the JVM (servlet engine)
I think.

What I am thinking to do is to set a upperbound memory usage in my
servlet, If servlet find out JVM is almost out of the memory, It will
block(stop process) anymore client request and just return an error
code like --> server busy something like that. That will prevent
servlet crash the VM.

I wonder if there is any better way? except calling gc().

Thanks.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / java.lang.outOfMemoryError
    Java program, unlike C program will swap to virtual memory if out of
    physical memory. Java only allocate a block of physical memory for
    JVM to run application.

    I have a servlet that will receive pretty heavy http request. There
    will be a chance of OutOfMemory Error if it receives too many request
    at a time.

    Any good way I can prevent OutOfMemoryError to happen? Since If the
    JVM throws an OutOfMemroyError, that means JVM is crashed and it will
    no longer function correctly until I restart the JVM (servlet engine)
    I think.

    What I am thinking to do is to set a upperbound memory usage in my
    servlet, If servlet find out JVM is almost out of the memory, It will
    block(stop process) anymore client request and just return an error
    code like --> server busy something like that. That will prevent
    servlet crash the VM.

    I wonder if there is any better way? except calling gc().

    Thanks.
    • with you method, you can also enlarge the heap of engine
    • You must release some objects if you don't want use them anymore,and gc will do something automatically