camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Do I have to give a ScheduledExecutorService instance when initializing DefualtTimeoutMap?
Date Thu, 09 Dec 2010 06:03:10 GMT
Hi

Yes you need to provide a scheduler if you want it to automatic purge
and timeout entries.

I have improved the source code to mandate a scheduler in the next release.
https://issues.apache.org/jira/browse/CAMEL-3416

On Thu, Dec 9, 2010 at 12:51 AM, yli <yimingLearnCamel@gmail.com> wrote:
>
> Hi All,
>      Recently I have this problem, which really making me confused.
>      In my code, I try to have a map where the items would expire after
> sometime and be deleted automatically, so I decided to use
> DefualtTimeoutMap. Here is how I initialize it:
>      "TimeoutMap myMap = new DefaultTimeoutMap(null, 1*60*1000L);"
>      As you can see I didn't passed in an instance of
> ScheduledExecutorService class(the first argument is null), because I
> thought since we have such a constructor, the ScheduledExecutorService
> should be taken care of behind the scene...
>      However, as it turned out, the "run" and "purge" methods didn't get
> executed, and the items in the map didn't get deleted after expired.
>      Then I looked at the source code of DefaultTimeoutMap class, I found:
>      ...
>      public DefaultTimeoutMap(ScheduledExecutorService executor, long
> requestMapPollTimeMillis, boolean useLock) {
>        this.executor = executor;
>        this.purgePollTime = requestMapPollTimeMillis;
>        this.useLock = useLock;
>        schedulePoll();
>    }
>
>      protected void schedulePoll() {
>        if (executor != null) {
>            executor.scheduleWithFixedDelay(this, initialDelay,
> purgePollTime, TimeUnit.MILLISECONDS);
>        }
>    }
>    ...
>    It looks like if executor is null, the scheduling won't start, in other
> words, we have to have a scheduler, is that right? If so, why do we have a
> constructor that allows null as scheduler?
>
>    Please correct me if there is anything I misunderstood. Thank you very
> much.
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Do-I-have-to-give-a-ScheduledExecutorService-instance-when-initializing-DefualtTimeoutMap-tp3298252p3298252.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Mime
View raw message