[ 
https://issues.apache.org/jira/browse/KAFKA-597?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13527168#comment-13527168
 ] 

Jay Kreps commented on KAFKA-597:
---------------------------------

Nice catch on the brace, will fix before check in.

With respect to the scaladoc, that is a legitimate call, I think. The api take 
default values so all of the following should work:
  scheduler.schedule("task", println("hello")) // immediately kick of a 
one-time background task
  scheduler.schedule("task", println("hello"), delay=50) // kick off a one-time 
task in 50ms
  scheduler.schedule("task", println("hello"), period = 50) // immediately kick 
off a repeating task that will repeat every 50 ms
  etc

WRT daemon, you are correct, but I don't think this is necessarily a bad thing. 
The requirement of the api is that you call startup() before calling schedule() 
and call shutdown() when done. Shutdown was previously a non-blocking call so 
it was very important whether the threads were blocking or non-blocking (but 
this functionality was totally *broken*) because you would likely call 
shutdown() and then exit the JVM. Now the only possible way to get to JVM 
shutdown with remaining scheduler threads is if your program has a bug and 
fails to call shutdown(). What should we do in this case? Hard to say. All 
tasks must handle unclean shutdown because unclean shutdown is a lot like a 
crash. Blocking JVM shutdown can really mess up automated deployment, so 
defaulting to that is not necessarily wise. So I am fine with either default 
but at least the consumer scheduler really needs to be set to daemon so we 
don't block people's jvms.
                
> Refactor KafkaScheduler
> -----------------------
>
>                 Key: KAFKA-597
>                 URL: https://issues.apache.org/jira/browse/KAFKA-597
>             Project: Kafka
>          Issue Type: Bug
>    Affects Versions: 0.8.1
>            Reporter: Jay Kreps
>            Priority: Minor
>         Attachments: KAFKA-597-v1.patch, KAFKA-597-v2.patch, 
> KAFKA-597-v3.patch, KAFKA-597-v4.patch, KAFKA-597-v5.patch
>
>
> It would be nice to cleanup KafkaScheduler. Here is what I am thinking
> Extract the following interface:
> trait Scheduler {
>   def startup()
>   def schedule(fun: () => Unit, name: String, delayMs: Long = 0, periodMs: 
> Long): Scheduled
>   def shutdown(interrupt: Boolean = false)
> }
> class Scheduled {
>   def lastExecution: Long
>   def cancel()
> }
> We would have two implementations, KafkaScheduler and  MockScheduler. 
> KafkaScheduler would be a wrapper for ScheduledThreadPoolExecutor. 
> MockScheduler would only allow manual time advancement rather than using the 
> system clock, we would switch unit tests over to this.
> This change would be different from the existing scheduler in a the following 
> ways:
> 1. Would not return a ScheduledFuture (since this is useless)
> 2. shutdown() would be a blocking call. The current shutdown calls, don't 
> really do what people want.
> 3. We would remove the daemon thread flag, as I don't think it works.
> 4. It returns an object which let's you cancel the job or get the last 
> execution time.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to