Let thread wait till memory is available  
Author Message
senges





PostPosted: 2007-5-10 21:40:00 Top

java-programmer, Let thread wait till memory is available hi all,
a basic question:

i have a memory consuming encoding process which runs in its own
thread.

To preseve OutOfMemory errors when a lot of those treads are running,
i want this thread to check the current memory heap, and maybe wait as
long as there's some available.

Is that possible ?
I think this must be a very common problem in thread programming?

Greets,
chris

 
Ingo R. Homann





PostPosted: 2007-5-10 21:45:00 Top

java-programmer >> Let thread wait till memory is available Hi,

senges wrote:
> hi all,
> a basic question:
>
> i have a memory consuming encoding process which runs in its own
> thread.
>
> To preseve OutOfMemory errors when a lot of those treads are running,
> i want this thread to check the current memory heap, and maybe wait as
> long as there's some available.
>
> Is that possible ?
> I think this must be a very common problem in thread programming?

You may take a look at java.lang.Runtime.free/max/totalMemory.

Hth,
Ingo

 
Robert Klemme





PostPosted: 2007-5-10 21:49:00 Top

java-programmer >> Let thread wait till memory is available On 10.05.2007 15:44, Ingo R. Homann wrote:
> Hi,
>
> senges wrote:
>> hi all,
>> a basic question:
>>
>> i have a memory consuming encoding process which runs in its own
>> thread.
>>
>> To preseve OutOfMemory errors when a lot of those treads are running,
>> i want this thread to check the current memory heap, and maybe wait as
>> long as there's some available.
>>
>> Is that possible ?
>> I think this must be a very common problem in thread programming?
>
> You may take a look at java.lang.Runtime.free/max/totalMemory.

Other options are to start and catch any OOM errors. Or use a thread
pool with limited size to limit concurrent processing.

Kind regards

robert
 
 
Ingo R. Homann





PostPosted: 2007-5-10 21:59:00 Top

java-programmer >> Let thread wait till memory is available Hi,

Robert Klemme wrote:
>>> hi all,
>>> a basic question:
>>>
>>> i have a memory consuming encoding process which runs in its own
>>> thread.
>>>
>>> To preseve OutOfMemory errors when a lot of those treads are running,
>>> i want this thread to check the current memory heap, and maybe wait as
>>> long as there's some available.
>>>
>>> Is that possible ?
>>> I think this must be a very common problem in thread programming?
>>
>> You may take a look at java.lang.Runtime.free/max/totalMemory.
>
> Other options are to start and catch any OOM errors.

But that might crash other threads (with low mem usage) with an OOME as
well!

> Or use a thread
> pool with limited size to limit concurrent processing.

OK.

Ciao,
Ingo