Skip to content

CAMEL-22949: Migrate components from Thread.sleep() to Camel's Task API#21215

Merged
gnodet merged 7 commits intoapache:mainfrom
gnodet:migrate-thread-sleep-to-task-api
Feb 2, 2026
Merged

CAMEL-22949: Migrate components from Thread.sleep() to Camel's Task API#21215
gnodet merged 7 commits intoapache:mainfrom
gnodet:migrate-thread-sleep-to-task-api

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Feb 2, 2026

This PR addresses CAMEL-22949 by migrating multiple components from using Thread.sleep() to Camel's Task API for better lifecycle management and integration with Camel's runtime.

Components Migrated

  1. camel-salesforce - Subscription retry logic with exponential backoff
  2. camel-aws2-athena - Query polling delays
  3. camel-zookeeper - Reconnection backoff logic
  4. camel-hazelcast - Error recovery delays in SEDA consumer
  5. camel-iggy - Busy-wait avoidance when suspended

Key Changes

  • Replace Thread.sleep() calls with Tasks.foregroundTask() using IterationBudget
  • Use withInitialDelay() for one-time delays (not withInterval() which only applies between iterations)
  • Proper integration with CamelContext for lifecycle management
  • Maintains existing behavior while improving resource management

Related Issues

Testing

  • All modified components compile successfully
  • Code style validation passes (-Psourcecheck)
  • Migration guide document added: MIGRATION_THREAD_SLEEP_TO_TASK_API.md

Replace Thread.sleep() with Tasks.foregroundTask() for subscription retry
backoff delay in SubscriptionHelper. This provides better integration with
Camel's lifecycle management and proper shutdown handling.
Replace Thread.sleep() with Tasks.foregroundTask() for query polling delay
in Athena2QueryHelper. This provides better integration with Camel's lifecycle
management and proper shutdown handling.
Replace Thread.sleep() with Tasks.foregroundTask() for reconnection backoff
delay in ZooKeeperConsumer. This provides better integration with Camel's
lifecycle management and proper shutdown handling.
Replace Thread.sleep() with Tasks.foregroundTask() for error recovery delay
in HazelcastSedaConsumer. This provides better integration with Camel's
lifecycle management and proper shutdown handling.
Replace Thread.sleep() with Tasks.foregroundTask() to avoid busy-waiting
when consumer is suspended in IggyFetchRecords. This provides better
integration with Camel's lifecycle management and proper shutdown handling.
…delays

The previous implementation used withInterval() which caused the task to
complete immediately without any delay. For a simple one-time delay, we
need to use withInitialDelay() which delays before the first iteration.
The ForegroundTask only sleeps between iterations, not before the first
iteration. For a simple one-time delay, we need to use withInitialDelay()
which delays before the first iteration.

This fixes test failures where the delay was not happening as expected.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

🌟 Thank you for your contribution to the Apache Camel project! 🌟

🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run

  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot.

  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.

  • Build and test logs are available in the Summary page. Only Apache Camel committers have access to the summary.

  • ⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@gnodet gnodet changed the title Migrate multiple components from Thread.sleep() to Camel's Task API CAMEL-22949: Migrate components from Thread.sleep() to Camel's Task API Feb 2, 2026
@gnodet gnodet merged commit 1b0fca1 into apache:main Feb 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants