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

  • Home
  • SEARCH
  • 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 7531173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:06:22+00:00 2026-05-30T05:06:22+00:00

Lets say I have a multi-threaded application that needs to resize some image files.

  • 0

Lets say I have a multi-threaded application that needs to resize some image files. I don’t want multiple thread to be able to resize the same image at the same time and overwrite each others result and corrupt the file, but to maximise concurrency I do want multiple threads to be able to resize different images at the same time.

What would be the best approach for a thread to acquire a lock on a specific image rather than simply synchronizing an entire block of code?

  • 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-30T05:06:23+00:00Added an answer on May 30, 2026 at 5:06 am
    • Use an fixed thread ExecutorService and have a thread which submits all of the images into the service to be processed. As long as you don’t submit the same image twice you won’t have a problem.

    • You could also have a thread which feeds the “todo” BlockingQueue for the other threads to consume. So then you have one thread that controls which images the threads work on so there would be no locks necessary.

    • Another way to do it would be to use a ConcurrentHashMap and have each thread putIfAbsent and then only consume the image only if it worked.

      if (concurrentMap.putIfAbsent(imagePath, null) == null) {
         // do the processing
         // either remove it from map when done or leave it to stop future processing
      }
      // I guess loop around and look at the next image
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a container (std::vector) of pointers used by a multi-threaded application.
Lets say I have a single object of type Car which I want to
Let's say I have a .NET user application (.exe) running under Windows that was
I have some difficulties understanding how Boost.MultiIndex is implemented. Lets say I have the
lets say I have a multi-line textbox with 100 lines, how would you go
If I have a data structure in a multithreaded application that I want to
Lets say I have an abstract base class and a derived class with some
Lets say I have a class that is doing something like: public class Foo
Let's say I have an android app, and in that app I want to
Let's say I have a multithreaded C++ program that handles requests in the form

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.