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 6002097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:55:43+00:00 2026-05-23T00:55:43+00:00

I start one thread to download contents from the internet, at one time, the

  • 0

I start one thread to download contents from the internet, at one time, the thread is downloading one file, and then i want it stop and begin to download another file, what should i do? should i count on the concurrency mechanism in java?

  • 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-05-23T00:55:44+00:00Added an answer on May 23, 2026 at 12:55 am

    You can start your thread using a single-thread executor, then when you kill it (gracefully I hope) and start a new one it will ensure that it’s using the same thread.

    // Suppose you have a DownloadFile class that implements Runnable
    DownloadFile task1 = new DownloadFile();
    
    ...
    
    ExecutorService exec = Executors.newSingleThreadExecutor();
    
    Future<Boolean> future = exec.submit( task1, Boolean.TRUE );
    
    ...
    
    // Cancel the task
    future.cancel();
    
    // Give the executor another task
    DownloadFile task2 = new DownloadFile();
    ...
    exec.submit( task2, Boolean.TRUE );
    

    Other useful docs:

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

Sidebar

Related Questions

I'm not able to start activity from thread. I want to start one activity
I have 4 threads and I want to start in one time 3 functions.
I created an application to download a file from URL. When I press start
What does it mean to move a object from one thread to another in
First one: how can I create a Thread that doesn't start right away.If I
I have a table that has two datetime columns (one for start time and
I need to transform one XML document into another using XSLT (for now from
I made a simple android application that moves from one activity to another activity
PHP as an Apache module or otherwise, would start one thread per pending request
I download a file by e.g. 5 threads. When one of the threads completes

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.