apache camel - How does Timer component polls? -
let's have following time component:
from("timer://foo?period=1000").setbody(constant("select * customer")).to("jdbc:testdb").to("beanref:processresult"); how timer component work here? reads database in every 1 sec or waits bean finish processing?
if bean still processing earlier result , timer keep polling database create bottleneck. there way avoid it?
okay, update: looking @ source code, timer component relies on java timertask implementation. , question answered here: is java's timer task guarenteed not run concurrently?
short answer: 1 single thread executes trigger , routes connected it, there no concurrent execution.
that said, might want controll execution bit. recommended timer tasks (and hence camel timers) have margin between period in timer , max task execution time.
you can use seda component (with concurrentconsumers=[num threads]) in between fine grain controll execution work queue. timer finish it's task right away while real route can continue process.
from("timer://foo?period=1000") .to("seda:startroute"); from("seda:startroute") .setbody(constant("select * customer")) .to("jdbc:testdb").to("beanref:processresult"); each event stack non less, on time, might want tune route period > avg route exec time.
you add shared boolean variable either in singleton bean or in static class:
public static synchronized boolean isrunning(){ return running; } public static synchronized void setrunning(boolean isrunning){ running = isrunning; } the variable should telling weather route running or not , filter timer events occurs while variable true. hook few processors/bean-calls handle this.
Comments
Post a Comment