classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] FYI: Implemented an ObjectPool: I think, the synchroniz


From: Meskauskas Audrius
Subject: Re: [cp-patches] FYI: Implemented an ObjectPool: I think, the synchronization is necessary.
Date: Fri, 01 Jul 2005 14:35:16 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)


Roman Kennke wrote:

I implemented and added an ObjectPool class.
I suggest to synchronize (pool) { before doing anything with it }. Otherwise the parallel threads time to time grab the same object from the pool, causing the total chaos inside the application.

Also, the pool may cause memory leak if the returnObject is called more often than borrowObject. Of course, this is only possible if some objects being returned were created outside the createObject, but the pool provides no any control on this. I suggest to control the balance of the borrowed/released objects or just put the size limit or use weak references.

Despite one instance of the pool seems sufficient, I suggest to leave its constructor public. The application with many parallel threads may prefer to have an array of pools, every time selecting a random member to operate. This helps against the loss of performance due necessity for other threads to wait while one of them is getting/returning an object.

The suggested pool will be highly effective on a machine with I think at least 4-8 processors. How on a single processor computer, I do not know.

Cheers
Audrius






reply via email to

[Prev in Thread] Current Thread [Next in Thread]