You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Syed Mudassir <sy...@gaiatv.in> on 2015/02/03 21:20:53 UTC

Apache common pooling 2

Guys,
   I have a question.
   I am using GenericKeyedObjectPool for pooling SFTP sessions. Suppose 
I have one session in the pool.
   Can this session be shared among multiple threads at the same time?
   I mean suppose if there are four threads running parallely, can this 
session be used at the same time by all the four threads simultaneously?
   If it is possible, any sample code to get it done?
-- 

Re: Apache common pooling 2

Posted by Bernd Eckenfels <ec...@zusammenkunft.net>.
Hello,

instead of the SFTP connections you can pool channels or sessions. Each
of them will only have a single borrower, but multiple threads could
use the same "physical" connection. 

This is possible because ssh protocol allows some multiplexing. But in
most scenarios I am not sure if the work is work it.

BTW: I think unlike JCA wich allows a seperation between logical
connections and managed connections the Pool does not offer a ready
solution for that kind of abstraction (especially not related to
tearing down all channels when one fails or initiating new physical
connections starting with a given utilisation).

Gruss
Bernd

BTW: something I would really like to see is a JDBC pool where you get
connection stubs which get bound late to actual JDBC sessions. This
helps code which holds on to the object and does not return it ASAP.


Am Tue, 3 Feb 2015 18:28:01 -0500
schrieb James Carman <ja...@carmanconsulting.com>:

> On Tue, Feb 3, 2015 at 5:07 PM, Matthew Huckaby
> <ma...@gmail.com> wrote:
> >
> > JC> Perhaps you'd be more interested in a "cache" rather than a
> > JC> "pool"?
> >
> > If the intention is to share an SFTP session/client reference
> > between threads, check-in and check-out could be important.
> >
> 
> I was assuming that the true intent was to really share the instances
> between threads.  If that's the case, then a cache might be more
> appropriate.  However, as you point out, it's probably not wise to
> share those connections with SFTP anyway, so pooling really is what
> you want.  You're going to have to do some form of serialization of
> the messages/requests (whatever they're called) going across that
> connection.  May as well let commons-pool do it for you by
> borrow/return pattern.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Apache common pooling 2

Posted by James Carman <ja...@carmanconsulting.com>.
On Tue, Feb 3, 2015 at 5:07 PM, Matthew Huckaby
<ma...@gmail.com> wrote:
>
> JC> Perhaps you'd be more interested in a "cache" rather than a "pool"?
>
> If the intention is to share an SFTP session/client reference between
> threads, check-in and check-out could be important.
>

I was assuming that the true intent was to really share the instances
between threads.  If that's the case, then a cache might be more
appropriate.  However, as you point out, it's probably not wise to
share those connections with SFTP anyway, so pooling really is what
you want.  You're going to have to do some form of serialization of
the messages/requests (whatever they're called) going across that
connection.  May as well let commons-pool do it for you by
borrow/return pattern.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Apache common pooling 2

Posted by Matthew Huckaby <ma...@gmail.com>.
SM>  Can this session be shared among multiple threads at the same time?

The GenericKeyedObjectPool API supports the behavior of borrowing and
returning objects:

borrowObject(Object key)
returnObject(Object key, Object obj)

This means that one thread would borrow the SFTP session/client object,
perform it's work, and then return it to the pool.
The 'borrow' would indicate that the object usage would be exclusive to the
borrower-thread until it is returned.

JC> Perhaps you'd be more interested in a "cache" rather than a "pool"?

If the intention is to share an SFTP session/client reference between
threads, check-in and check-out could be important.

Although I do not know the use-case, I would imagine that each SFTP session
would likely need to be borrowed from the pool exclusively for some set of
FTP-commands and then returned once the intended set of steps had been
completed. Otherwise, the various threads might issue commands to the
session/client that would interrupt each other.

Because GenericKeyedObjectPool supports exclusivity, testing idle, idle
object evictor, and ensuring a minimum number of idle objects, it would be
ideal for maintaining a connection to an SFTP server, where a simple cache
could eventually be holding onto stale objects or clients having closed
connections.

- MDH



On Tue, Feb 3, 2015 at 3:21 PM, James Carman <ja...@carmanconsulting.com>
wrote:

> Perhaps you'd be more interested in a "cache" rather than a "pool"?
>
> On Tue, Feb 3, 2015 at 3:20 PM, Syed Mudassir <sy...@gaiatv.in>
> wrote:
>
>>  Guys,
>>   I have a question.
>>   I am using GenericKeyedObjectPool for pooling SFTP sessions.  Suppose I
>> have one session in the pool.
>>   Can this session be shared among multiple threads at the same time?
>>   I mean suppose if there are four threads running parallely, can this
>> session be used at the same time by all the four threads simultaneously?
>>   If it is possible, any sample code to get it done?
>> --
>>
>
>


-- 
(847) 494-2866

Re: Apache common pooling 2

Posted by James Carman <ja...@carmanconsulting.com>.
Perhaps you'd be more interested in a "cache" rather than a "pool"?

On Tue, Feb 3, 2015 at 3:20 PM, Syed Mudassir <sy...@gaiatv.in>
wrote:

>  Guys,
>   I have a question.
>   I am using GenericKeyedObjectPool for pooling SFTP sessions.  Suppose I
> have one session in the pool.
>   Can this session be shared among multiple threads at the same time?
>   I mean suppose if there are four threads running parallely, can this
> session be used at the same time by all the four threads simultaneously?
>   If it is possible, any sample code to get it done?
> --
>