Timeout for GParsExecutorsPool callAsync?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Timeout for GParsExecutorsPool callAsync?

sbrake
I'm using GParsExecutorsPool to run some asynchronous tasks in a manner similar to the following:

GParsExecutorsPool.withExistingPool threadPoolExecutor, {
        def myClosure = {
              ... Something that takes a long time to do
        }
        myClosure.callAsync()
}

I would like to be able to add a time out to this call if it takes over a minute.  java.util.concurrent.Future has a get(int, TimeUnit) function that allows for this, but I'm not seeing something similar using callAsync.  Is there a way to accomplish setting the timeout, or is this an enhancement that can be logged?
Reply | Threaded
Open this post in threaded view
|

Re: Timeout for GParsExecutorsPool callAsync?

Alex Miller
callAsync returns the Future which you can do with as you will (like calling get with a timeout).


From: sbrake <[hidden email]>
To: [hidden email]
Sent: Wed, August 4, 2010 5:43:19 PM
Subject: [gpars-user] Timeout for GParsExecutorsPool callAsync?


I'm using GParsExecutorsPool to run some asynchronous tasks in a manner
similar to the following:

GParsExecutorsPool.withExistingPool threadPoolExecutor, {
        def myClosure = {
              ... Something that takes a long time to do
        }
        myClosure.callAsync()
}

I would like to be able to add a time out to this call if it takes over a
minute.  java.util.concurrent.Future has a get(int, TimeUnit) function that
allows for this, but I'm not seeing something similar using callAsync.  Is
there a way to accomplish setting the timeout, or is this an enhancement
that can be logged?
--
View this message in context: http://gpars-user-mailing-list.19372.n3.nabble.com/Timeout-for-GParsExecutorsPool-callAsync-tp1024214p1024214.html
Sent from the GPars - user mailing list mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Timeout for GParsExecutorsPool callAsync?

sbrake
If I do that, my service then waits for the thread to complete before returning, which is not what we want either.

On Wed, Aug 4, 2010 at 8:56 PM, Alex Miller [via GPars - user mailing list] <[hidden email]> wrote:
callAsync returns the Future which you can do with as you will (like calling get with a timeout).


From: sbrake <[hidden email]>
To: [hidden email]
Sent: Wed, August 4, 2010 5:43:19 PM
Subject: [gpars-user] Timeout for GParsExecutorsPool callAsync?


I'm using GParsExecutorsPool to run some asynchronous tasks in a manner
similar to the following:

GParsExecutorsPool.withExistingPool threadPoolExecutor, {
        def myClosure = {
              ... Something that takes a long time to do
        }
        myClosure.callAsync()
}

I would like to be able to add a time out to this call if it takes over a
minute.  java.util.concurrent.Future has a get(int, TimeUnit) function that
allows for this, but I'm not seeing something similar using callAsync.  Is
there a way to accomplish setting the timeout, or is this an enhancement
that can be logged?
--
View this message in context: http://gpars-user-mailing-list.19372.n3.nabble.com/Timeout-for-GParsExecutorsPool-callAsync-tp1024214p1024214.html
Sent from the GPars - user mailing list mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email









--
In wine there is wisdom, in beer strength and in water- bacteria.
Reply | Threaded
Open this post in threaded view
|

Re: Timeout for GParsExecutorsPool callAsync?

Alex Miller
One perhaps complicated answer would be to use a separate ScheduledExecutorService that handled the timeout actions.  You would callAsync on the first pool which would return a Future.  You would then wrap that Future into a task and give it to a ScheduledExecutorService with the schedule() call and the timeout.  After the delay, the scheduled task would wake up and do something like:

if(! future.isDone()) {
  future.cancel()
}

GPars doesn't have explicit support for ScheduledExecutorService, but you could create and pass the entire service to withExistingPool to use one.  

It would be nice if something wrapped all this up for you of course.  I don't know of anything like that in either Java or GPars.  


From: sbrake <[hidden email]>
To: [hidden email]
Sent: Thu, August 5, 2010 8:49:17 AM
Subject: [gpars-user] Re: Timeout for GParsExecutorsPool callAsync?


If I do that, my service then waits for the thread to complete before
returning, which is not what we want either.

On Wed, Aug 4, 2010 at 8:56 PM, Alex Miller [via GPars - user mailing list]
<ml-node+[hidden email]<ml-node%[hidden email]>
> wrote:

> callAsync returns the Future which you can do with as you will (like
> calling get with a timeout).
>
> ------------------------------
> *From:* sbrake <[hidden email]<http://user/SendEmail.jtp?type=node&node=1024616&i=0>
> >
> *To:* [hidden email]<http://user/SendEmail.jtp?type=node&node=1024616&i=1>

> *Sent:* Wed, August 4, 2010 5:43:19 PM
> *Subject:* [gpars-user] Timeout for GParsExecutorsPool callAsync?
>
>
> I'm using GParsExecutorsPool to run some asynchronous tasks in a manner
> similar to the following:
>
> GParsExecutorsPool.withExistingPool threadPoolExecutor, {
>        def myClosure = {
>              ... Something that takes a long time to do
>        }
>        myClosure.callAsync()
> }
>
> I would like to be able to add a time out to this call if it takes over a
> minute.  java.util.concurrent.Future has a get(int, TimeUnit) function that
> allows for this, but I'm not seeing something similar using callAsync.  Is
> there a way to accomplish setting the timeout, or is this an enhancement
> that can be logged?
> --
> View this message in context:
> http://gpars-user-mailing-list.19372.n3.nabble.com/Timeout-for-GParsExecutorsPool-callAsync-tp1024214p1024214.html<http://gpars-user-mailing-list.19372.n3.nabble.com/Timeout-for-GParsExecutorsPool-callAsync-tp1024214p1024214.html?by-user=t>
> Sent from the GPars - user mailing list mailing list archive at Nabble.com<http://Nabble.com?by-user=t>
> .
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
>
> ------------------------------
>  View message @
> http://gpars-user-mailing-list.19372.n3.nabble.com/Timeout-for-GParsExecutorsPool-callAsync-tp1024214p1024616.html
> To unsubscribe from Timeout for GParsExecutorsPool callAsync?, click here<http://gpars-user-mailing-list.19372.n3.nabble.com/subscriptions/Unsubscribe.jtp?code=c2FyYWguYnJha2VAZ21haWwuY29tfDEwMjQyMTR8MTY4OTMwNjU1>.
>
>
>


--
In wine there is wisdom, in beer strength and in water- bacteria.

--
View this message in context: http://gpars-user-mailing-list.19372.n3.nabble.com/Timeout-for-GParsExecutorsPool-callAsync-tp1024214p1026266.html
Sent from the GPars - user mailing list mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Timeout for GParsExecutorsPool callAsync?

Vaclav
Administrator
Thank you, guys, for the suggestions. To me it looks like something worth supporting - http://jira.codehaus.org/browse/GPARS-93

Vaclav


On Mon, Aug 9, 2010 at 8:22 AM, Alex Miller <[hidden email]> wrote:
One perhaps complicated answer would be to use a separate ScheduledExecutorService that handled the timeout actions.  You would callAsync on the first pool which would return a Future.  You would then wrap that Future into a task and give it to a ScheduledExecutorService with the schedule() call and the timeout.  After the delay, the scheduled task would wake up and do something like:

if(! future.isDone()) {
  future.cancel()
}

GPars doesn't have explicit support for ScheduledExecutorService, but you could create and pass the entire service to withExistingPool to use one.  

It would be nice if something wrapped all this up for you of course.  I don't know of anything like that in either Java or GPars.  


From: sbrake <[hidden email]>
To: [hidden email]
Sent: Thu, August 5, 2010 8:49:17 AM
Subject: [gpars-user] Re: Timeout for GParsExecutorsPool callAsync?


If I do that, my service then waits for the thread to complete before
returning, which is not what we want either.

On Wed, Aug 4, 2010 at 8:56 PM, Alex Miller [via GPars - user mailing list]
<ml-node+[hidden email]<ml-node%[hidden email]>
> wrote:

> callAsync returns the Future which you can do with as you will (like
> calling get with a timeout).
>
> ------------------------------
> *From:* sbrake <[hidden email]<http://user/SendEmail.jtp?type=node&node=1024616&i=0>
> >
> *To:* [hidden email]<http://user/SendEmail.jtp?type=node&node=1024616&i=1>
> *Sent:* Wed, August 4, 2010 5:43:19 PM
> *Subject:* [gpars-user] Timeout for GParsExecutorsPool callAsync?
>
>
> I'm using GParsExecutorsPool to run some asynchronous tasks in a manner
> similar to the following:
>
> GParsExecutorsPool.withExistingPool threadPoolExecutor, {
>        def myClosure = {
>              ... Something that takes a long time to do
>        }
>        myClosure.callAsync()
> }
>
> I would like to be able to add a time out to this call if it takes over a
> minute.  java.util.concurrent.Future has a get(int, TimeUnit) function that
> allows for this, but I'm not seeing something similar using callAsync.  Is
> there a way to accomplish setting the timeout, or is this an enhancement
> that can be logged?
> --
> View this message in context:
> http://gpars-user-mailing-list.19372.n3.nabble.com/Timeout-for-GParsExecutorsPool-callAsync-tp1024214p1024214.html<http://gpars-user-mailing-list.19372.n3.nabble.com/Timeout-for-GParsExecutorsPool-callAsync-tp1024214p1024214.html?by-user=t>
> Sent from the GPars - user mailing list mailing list archive at Nabble.com<http://Nabble.com?by-user=t>
> .
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
>
> ------------------------------
>  View message @
> http://gpars-user-mailing-list.19372.n3.nabble.com/Timeout-for-GParsExecutorsPool-callAsync-tp1024214p1024616.html
> To unsubscribe from Timeout for GParsExecutorsPool callAsync?, click here<http://gpars-user-mailing-list.19372.n3.nabble.com/subscriptions/Unsubscribe.jtp?code=c2FyYWguYnJha2VAZ21haWwuY29tfDEwMjQyMTR8MTY4OTMwNjU1>.
>
>
>


--
In wine there is wisdom, in beer strength and in water- bacteria.

--
View this message in context: http://gpars-user-mailing-list.19372.n3.nabble.com/Timeout-for-GParsExecutorsPool-callAsync-tp1024214p1026266.html
Sent from the GPars - user mailing list mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





--
E-mail: [hidden email]
Blog: http://www.jroller.com/vaclav
Linkedin page: http://www.linkedin.com/in/vaclavpech