Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:24:52+00:00 2026-06-13T01:24:52+00:00

I have a simple file transfer application that is run as a standalone Java

  • 0

I have a simple file transfer application that is run as a standalone Java application. It takes files from an SFTP endpoint and moves them to another endpoint.

Files are deleted from the SFTP endpoint after they are transferred. When there are no more files left, it would be ideal to have the program end. However, I haven’t been able to find a solution where I can start Camel and get it to end conditionally (like when there are no more files in the SFTP endpoint). My workaround is currently to start Camel and then have the main thread sleep for a very long time. The user then has to kill the application manually (via CTRL+C or otherwise).

Is there a better way to have the application terminate such that it does so automatically?

Below is my current code:

In CamelContext (Spring App Context):

<route>
    <from uri="sftp:(url)" />
    <process ref="(processor)" />
    <to uri="(endpoint)" />
</route>

main() method:

public static void main(String[] args)
{
  ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
  CamelContext camelContext = appContext.getBean(CamelContext.class);

  try
  {
    camelContext.start();
    Thread.sleep(1000000000); // Runs the program for a long time -- is there a better way?
  }
  catch (Exception e)
  {
    e.printStackTrace();
  }

  UploadContentLogger.info("Exiting");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:24:53+00:00Added an answer on June 13, 2026 at 1:24 am

    You could change you route something like this:

    <route>
        <from uri="sftp:(url)?sendEmptyMessageWhenIdle=true" />
        <choose>
            <when>
                <simple>${body} != null</simple>
                <process ref="(processor)" />
                <to uri="(endpoint)" />
            </when>
            <otherwise>
                <process ref="(shutdownProcessor)" />
            </otherwise>
        </choose>
    </route>
    

    Notice using sendEmptyMessageWhenIdle=true

    And here is shutdownProcessor

    public class ShutdownProcessor {
        public void stop(final Exchange exchange) {
            new Thread() {
                @Override
                public void run() {
                    try {
                        exchange.getContext().stop();
                    } catch (Exception e) {
                        // log error
                    }
                }
            }.start();
        }
    }
    

    Actually I didn’t run this code, but it should work as desired.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple file transfer application, which transfers 4096 bytes per write from
I have a very simple file transfer application (C# .NET) that allows users to
I have a file transfer application (large files) and I want to make it
We have a client/server application that needs to transfer the same large files to,
I have a simple file browser and there I display files and folders, obtained
I have a simple JavaScript file that has three jQuery $document.ready functions. All three
i have a simple xml file in a wcf service that i am trying
I have an application that processes file transfers. In some instances, I need to
I have a simple file transfer socket program where one socket sends file data
I have a simple script that allows someone to download a movie file to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.