On 02/03/2013 10:56 AM, Michael Pasternak wrote:
On 01/31/2013 12:50 AM, Moti Asayag wrote:
> On 01/29/2013 10:27 AM, navin p wrote:
>>> Hi,
>>> I wrote this sample code and the resident memory of the process is
>>> increasing gradually over time. What could be the reason ? I don't see
>>> any obvious leaks in my program. Could it be that the API is not
>>> freeing/deleting memory ?
> By monitoring the program, it seems that the failure is due to constant
> threads creation by invoking the "new API()" call:
>
> Exception in thread "main" java.lang.OutOfMemoryError: unable to create
> new native thread
> at java.lang.Thread.start0(Native Method)
> at java.lang.Thread.start(Thread.java:691)
> at
>
org.ovirt.engine.sdk.web.ConnectionsPoolBuilder.createPoolingClientConnectionManager(ConnectionsPoolBuilder.java:182)
> at
>
org.ovirt.engine.sdk.web.ConnectionsPoolBuilder.createDefaultHttpClient(ConnectionsPoolBuilder.java:160)
> at
>
org.ovirt.engine.sdk.web.ConnectionsPoolBuilder.build(ConnectionsPoolBuilder.java:234)
> at org.ovirt.engine.sdk.Api.<init>(Api.java:82)
> at collectHosts.main(collectHosts.java:102)
>
>
> By pulling the API instantiation outside of the loop, problem solved,
> since only a single thread is created to monitor the idle/expired
> connections.
Thanks Moti,
I already suggested navin to take SDK proxy initiation out of his while loop.
>
>
> Michael, wouldn't you suggest adding some sort of API.shutdown() method
> in order to release resources used by it including the connection
> monitor and any other live connections if exists?
no need for that, in SDK i have dedicated thread (watchdog) for that.
But what if you wish to instantiate several API classes? each of them
will leave a detached (daemon) thread for monitoring the connections.
I suggested to perform inside the API.shutdown() release of any resource
used by it, including the watchdog thread. Else there is a sort of
thread-leak: when you have no longer reference to the API object, yet
the thread used to clean connections open by it is still running.
>