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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:17:44+00:00 2026-06-08T08:17:44+00:00

Can I ask a rookie Java question? I am downloading some files from the

  • 0

Can I ask a rookie Java question?

I am downloading some files from the web. This method download(url location) is called multiple times.

public static void download(final String url) {
    Thread t = new Thread("download") {
        @Override
        public void run() {
            try {
                synchronized (object) {
                    // download & save
                }
            } catch(Exception e) {}
        }
    };
    t.start();
}

I added “synchronized” so that downloads happens one-by-one. (not multiple downloads occur at the same time).
I am guessing even though download() is called multiple times, synchronized will block other threads until the first thread is finished.

Will above code work? or do I have to implement Queue? and dequeue one-by-one?
Can synchronized block “enough” threads? (30? 50?) or does it have limits?

  • 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-08T08:17:45+00:00Added an answer on June 8, 2026 at 8:17 am

    Will above code work?

    Yes, as long as object refers to the same object in all threads, the code in the synchronized block will only be executed by one thread at a time.

    […] or do I have to implement Queue? and dequeue one-by-one?

    Generally speaking I would recommend you to use as high-level constructs as possible (for instance from the java.util.concurrent package). You may for instance consider using an executor service for these types of things.

    […] Can synchronized block “enough” threads? (30? 50?) or does it have limits?

    No, no limits. At least not near 30 or 50 🙂

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

Sidebar

Related Questions

I'm trying to invoke the method from this string so that I can ask
Im not sure if I can ask such question here, since this has to
I'm not quite sure if I can ask this question here or on SuperUser
I think the simplest way I can ask this question is with an example:
who recommend me a professional computer vision web site so i can ask question
I don't know if I can ask this question here. I usually mistake, but...
I'm going to preface with: I hope I can ask this question here, because
im new with regexp, so can i ask for some assistance Using string.replace function
Hopefully I can ask this without being confusing. I am a photographer and I
This may be a rookie question but if I have created a suite of

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.