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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:15:01+00:00 2026-05-23T16:15:01+00:00

This snippet is from JCIP (Brian Goetz) listing 6.15 f.get() throws InterruptedException and ExecutionException.

  • 0

This snippet is from JCIP (Brian Goetz) listing 6.15

f.get() throws InterruptedException and ExecutionException. Now, these exceptions are specific to the future correct?
Meaning the specific task represented by the future was interrupted or had an internal exception.

Questions –

  1. Why do I need to restore the interrupt using “Thread.currentThread().interrupt()”? , because isnt the interrupt flag for the thread my task ran in? This is a little confusing.

  2. Why throw launderThrowable exception? If one of the downloadImage had an issue, shouldnt we just process the other downloaded images intead of throwing from here and thus just “not” processing the remaining futures?

    package net.jcip.examples;
    
    import java.util.*;
    import java.util.concurrent.*;
    import static net.jcip.examples.LaunderThrowable.launderThrowable;
    
    /**
     * Renderer
     * <p/>
     * Using CompletionService to render page elements as they become available
     *
     * @author Brian Goetz and Tim Peierls
     */
    public abstract class Renderer {
        private final ExecutorService executor;
    
        Renderer(ExecutorService executor) {
            this.executor = executor;
        }
    
        void renderPage(CharSequence source) {
            final List<ImageInfo> info = scanForImageInfo(source);
            CompletionService<ImageData> completionService =
                    new ExecutorCompletionService<ImageData>(executor);
            for (final ImageInfo imageInfo : info)
                completionService.submit(new Callable<ImageData>() {
                    public ImageData call() {
                        return imageInfo.downloadImage();
                    }
                });
    
            renderText(source);
    
            try {
                for (int t = 0, n = info.size(); t < n; t++) {
                    Future<ImageData> f = completionService.take();
                    ImageData imageData = f.get();
                    renderImage(imageData);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            } catch (ExecutionException e) {
                throw launderThrowable(e.getCause());
            }
        }
    
        interface ImageData {
        }
    
        interface ImageInfo {
            ImageData downloadImage();
        }
    
        abstract void renderText(CharSequence s);
    
        abstract List<ImageInfo> scanForImageInfo(CharSequence s);
    
        abstract void renderImage(ImageData i);
    
    }
    
  • 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-23T16:15:01+00:00Added an answer on May 23, 2026 at 4:15 pm
    1. The interruption does not necessarily happen on the thread pool’s thread. The interruption is for a point when your current thread is interrupted while you are waiting on the future’s get to complete. For instance, if you made the Future accessible to another part of the program that can cancel the download, then Future.cancel(true) will cause that InterruptedException to occur which you can then clean up the rest of the data. And as Beohemaian mentioned, it is always safe to propogate the interruption.

    2. Thats a good question. I think that was more of a design choice of what he wanted it to do. But you can easily hold onto that error and throw it after the rest complete. Something to think about though, what if its an OutOfMemoryError? Then the launder would be useful to only throw if its an Error and maybe not a RuntimeException.

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

Sidebar

Related Questions

I got code snippet from this site, which I used as shown below $data
I found this snippet: def timesince(dt, default=just now): now = datetime.utcnow() diff = now
Here's a snippet from my csproj file: <ProjectReference Include=..\program_data\program_data.csproj Condition='$(Configuration)'=='Debug'> <Project>{4F9034E0-B8E3-448E-8794-CF9B9A5E7D46}</Project> <Name>program_data</Name> </ProjectReference> What
I am having trouble using system() from libc on Linux. My code is this:
While bringing an application from .NET 3.5 to .NET 4.0 I've run into this
I put this code in my home.phtml, but nothing is shown. I took this
I'm following from an example of sending an email with image attachment through mail().
Shown below is a snippet of code where I try and reference my ApplicationProperties
I have the following variables defined: def VAL1 = 'foo' def VAL2 = 'bar'
i want to implement a google map based on its api. i want 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.