[
https://issues.apache.org/jira/browse/CAMEL-26596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Daniel Schmid updated CAMEL-26596:
----------------------------------
Description:
h2. The bug
The FileConsumer#doStart method calls {{super.doStart()}} twice, once in and
once outside of the {{{}try{}}}-block:
[https://github.com/apache/camel/blob/da3c53374e32e0f82ec5b862e5bc9b471ae511c2/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java#L472-L500]
h2. The effect
This will cause some parts of the startup logic unnecessarily being executed
twice. One instance of this happening is {{ScheduledPollConsumer#doStart}}
calling {{scheduler.scheduleTask(this);}} twice:
[https://github.com/apache/camel/blob/da3c53374e32e0f82ec5b862e5bc9b471ae511c2/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java#L703]
Because the {{DefaultScheduledPollConsumerScheduler#scheduleTask}} replaces the
old task with the new one, this means that this bug (seemingly) has no affect
with the default scheduler. However, custom schedulers may want to support
being used across multiple routes:
{code:java}
// example code for a scheduler where the same scheduler object/bean may be
used in multiple routes
public class MultiScheduler extends DefaultScheduledPollConsumerScheduler {
private List<Runnable> taskList;
@Override
public synchronized void scheduleTask(Runnable task) {
if (taskList == null) {
taskList = new ArrayList<>();
super.scheduleTask(this::runAll);
}
taskList.add(task);
}
private synchronized void runAll() {
taskList.forEach(Runnable::run);
}
}{code}
If a {{FileConsumer}} is used with a scheduler like this, each schedule will
run it twice (so the polling happens twice).
h2. Suggested fix
{{AbstractSftpConsumer}} [implements the same pattern
correctly|https://github.com/apache/camel/blob/da3c53374e32e0f82ec5b862e5bc9b471ae511c2/components/camel-ftp-common/src/main/java/org/apache/camel/component/file/remote/AbstractSftpConsumer.java#L67-L93]
without the duplicate {{super.doStart()}} call. {{FileConsumer}} should work
similar to that and the second {{super.doStart();}} should be removed.
was:
h2. The bug
The FileConsumer#doStart method calls {{super.doStart()}} twice, once in and
once outside of the {{{}try{}}}-block:
[https://github.com/apache/camel/blob/da3c53374e32e0f82ec5b862e5bc9b471ae511c2/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java#L472-L500]
h2. The effect
This will cause some parts of the startup logic unnecessarily being executed
twice. One instance of this happening is {{ScheduledPollConsumer#doStart}}
calling {{scheduler.scheduleTask(this);}} twice:
[https://github.com/apache/camel/blob/da3c53374e32e0f82ec5b862e5bc9b471ae511c2/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java#L703]
Because the {{DefaultScheduledPollConsumerScheduler#scheduleTask}} replaces the
old task with the new one, this means that this bug (seemingly) has no affect
with the default scheduler. However, custom schedulers may want to support
being used across multiple routes:
{code:java}
// example code for a scheduler where the same scheduler object/bean may be
used in multiple routes
public class MultiScheduler extends DefaultScheduledPollConsumerScheduler {
private List<Runnable> taskList;
@Override
public synchronized void scheduleTask(Runnable task) {
if (taskList == null) {
taskList = new ArrayList<>();
super.scheduleTask(this::runAll);
}
taskList.add(task);
}
private void runAll() {
taskList.forEach(Runnable::run);
}
}{code}
If a {{FileConsumer}} is used with a scheduler like this, each schedule will
run it twice (so the polling happens twice).
h2. Suggested fix
{{AbstractSftpConsumer}} [implements the same pattern
correctly|https://github.com/apache/camel/blob/da3c53374e32e0f82ec5b862e5bc9b471ae511c2/components/camel-ftp-common/src/main/java/org/apache/camel/component/file/remote/AbstractSftpConsumer.java#L67-L93]
without the duplicate {{super.doStart()}} call. {{FileConsumer}} should work
similar to that and the second {{super.doStart();}} should be removed.
> FileConsumer calls super.doStart() twice causing duplicate scheduling
> ---------------------------------------------------------------------
>
> Key: CAMEL-26596
> URL: https://issues.apache.org/jira/browse/CAMEL-26596
> Project: Camel
> Issue Type: Bug
> Components: camel-file, camel-scheduler
> Affects Versions: 4.18.5, 4.22.2, 4.23.0
> Reporter: Daniel Schmid
> Assignee: Claus Ibsen
> Priority: Minor
> Labels: easyfix
> Fix For: 4.24.0
>
>
> h2. The bug
> The FileConsumer#doStart method calls {{super.doStart()}} twice, once in and
> once outside of the {{{}try{}}}-block:
> [https://github.com/apache/camel/blob/da3c53374e32e0f82ec5b862e5bc9b471ae511c2/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java#L472-L500]
> h2. The effect
> This will cause some parts of the startup logic unnecessarily being executed
> twice. One instance of this happening is {{ScheduledPollConsumer#doStart}}
> calling {{scheduler.scheduleTask(this);}} twice:
> [https://github.com/apache/camel/blob/da3c53374e32e0f82ec5b862e5bc9b471ae511c2/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java#L703]
>
> Because the {{DefaultScheduledPollConsumerScheduler#scheduleTask}} replaces
> the old task with the new one, this means that this bug (seemingly) has no
> affect with the default scheduler. However, custom schedulers may want to
> support being used across multiple routes:
>
> {code:java}
> // example code for a scheduler where the same scheduler object/bean may be
> used in multiple routes
> public class MultiScheduler extends DefaultScheduledPollConsumerScheduler {
> private List<Runnable> taskList;
> @Override
> public synchronized void scheduleTask(Runnable task) {
> if (taskList == null) {
> taskList = new ArrayList<>();
> super.scheduleTask(this::runAll);
> }
> taskList.add(task);
> }
> private synchronized void runAll() {
> taskList.forEach(Runnable::run);
> }
> }{code}
> If a {{FileConsumer}} is used with a scheduler like this, each schedule will
> run it twice (so the polling happens twice).
>
> h2. Suggested fix
> {{AbstractSftpConsumer}} [implements the same pattern
> correctly|https://github.com/apache/camel/blob/da3c53374e32e0f82ec5b862e5bc9b471ae511c2/components/camel-ftp-common/src/main/java/org/apache/camel/component/file/remote/AbstractSftpConsumer.java#L67-L93]
> without the duplicate {{super.doStart()}} call. {{FileConsumer}} should work
> similar to that and the second {{super.doStart();}} should be removed.
>
>
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)