Equivalent of scheduleAtFixedRate() for Callable

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

Equivalent of scheduleAtFixedRate() for Callable

Andrew Lentvorski
I hope I'm not missing anything obvious, but I can't seem to find the
equivalents to scheduleAtFixedRate() and scheduleAtFixedDelay() for
Callable classes.

Did I miss something?  If not, what is the equivalent idiom?

Thanks,
-a

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Equivalent of scheduleAtFixedRate() for Callable

Joe Bowbeer
See ScheduledExecutorService

http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html

On 3/25/06, Andrew Lentvorski <[hidden email]> wrote:
> I hope I'm not missing anything obvious, but I can't seem to find the
> equivalents to scheduleAtFixedRate() and scheduleAtFixedDelay() for
> Callable classes.
>
> Did I miss something?  If not, what is the equivalent idiom?
>

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Equivalent of scheduleAtFixedRate() for Callable

Joe Bowbeer
I was assuming you were arriving from java.util.Timer land, but maybe
you already have seen ScheduledExecutorService, where periodic
execution of Runnable *is* all you get.

If you need to report a periodic result from a Callable you'll need to
incorporate your own mechanism for doing that, such as a Listener.  SO
you'd wrap your Callable in a Runnable like the following before
scheduling it for periodic execution.

  new Runnable() {
      public void run() {
          listener.hear(callable.call());
      }
  }


On 3/25/06, Joe Bowbeer <[hidden email]> wrote:

> See ScheduledExecutorService
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html
>
> On 3/25/06, Andrew Lentvorski <[hidden email]> wrote:
> > I hope I'm not missing anything obvious, but I can't seem to find the
> > equivalents to scheduleAtFixedRate() and scheduleAtFixedDelay() for
> > Callable classes.
> >
> > Did I miss something?  If not, what is the equivalent idiom?
> >
>

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Equivalent of scheduleAtFixedRate() for Callable

Andrew Lentvorski
Joe Bowbeer wrote:
> I was assuming you were arriving from java.util.Timer land

Wrong assumption.  I use Runnable and scheduleAtFixedRate() just fine.  ;)

>, but maybe
> you already have seen ScheduledExecutorService, where periodic
> execution of Runnable *is* all you get.

Yep, and that is my problem.

> If you need to report a periodic result from a Callable you'll need to
> incorporate your own mechanism for doing that, such as a Listener.  SO
> you'd wrap your Callable in a Runnable like the following before
> scheduling it for periodic execution.
>
>   new Runnable() {
>       public void run() {
>           listener.hear(callable.call());
>       }
>   }

Yuck.  But I'll keep it in mind.

Is the lack of scheduleAtFixedRate() et al. for Callable a conscious
design decision or is it just an oversight?  Or, in slightly different
form, is there some minefield with Callable and scheduleAtFixedRate()
that the experts know about that I'm about to go plowing into?

Thanks,
-a

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Equivalent of scheduleAtFixedRate() for Callable

Joe Bowbeer
On 3/25/06, Andrew Lentvorski <[hidden email]> wrote:
>
> Is the lack of scheduleAtFixedRate() et al. for Callable a conscious
> design decision or is it just an oversight?  Or, in slightly different
> form, is there some minefield with Callable and scheduleAtFixedRate()
> that the experts know about that I'm about to go plowing into?
>

Yes it was conscious.  Runnable seemed like a better match to periodic
execution, conceptually.

I don't think I understand how you would like the periodic execution
for Callable to be implemented.  (In my mind's eye, scheduling a
Callable for periodic execution would be like one hand clapping..)

Joe.

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Equivalent of scheduleAtFixedRate() for Callable

Brian Goetz
In reply to this post by Andrew Lentvorski
What would such a thing do with the result?  Where would it report an
exception?

A Runnable is a task -- "do something".  A Callable is a function --
"compute something".  Callable is typically used for things you only
need to compute the result of once.

If Callable is a Runnable with a return value, it stands to reason that
you would use a Callable when some activity wants to retrieve that
value.  In the case of scheduling a recurring task, who is retrieving
the value, and what are they doing with it?

Andrew Lentvorski wrote:
> I hope I'm not missing anything obvious, but I can't seem to find the
> equivalents to scheduleAtFixedRate() and scheduleAtFixedDelay() for
> Callable classes.
>
> Did I miss something?  If not, what is the equivalent idiom?

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest