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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:51:18+00:00 2026-05-24T23:51:18+00:00

I am new to java.util.concurrent package. I’m trying to write some samples. Here is

  • 0

I am new to java.util.concurrent package. I’m trying to write some samples.
Here is my some sample code snippet:

for (MyTask task : tasks) { 
Future<Boolean> result = task.getResult();
try {
    if (result.isCancelled()) {
        logger.info("processResults():  cancelled: "+ ((MyTask) task).getName());
    } else if (result.get() == false) {
        logger.info("processResults(): Failed : "+ ((MyTask) task).getName());
    } else {
        logger.info("processResults(): successful: "+ ((MyTask) task).getName());
        tasks.remove(task);
        continue; 
    }
} catch (Exception e) {
    logger.warn("processResults(): Excepiton: " + e.getMessage());
} 
}

I have one question regarding the handling the Future object from worker thread. in my for loop the handling of tasks is in sequential manner; lets say, I need to process the return results from the worker thread, if my 2nd worker thread is completed before the first one, in my code there is no way to process the 2nd worker thread first.

Can anybody suggest the best way to handle current threds.

Thanks,
Venkat Papana

  • 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-24T23:51:19+00:00Added an answer on May 24, 2026 at 11:51 pm

    If you want to perform some work as soon as the task finishes you can do that in the same thread. i.e. change the task to do everything and have it return a value after everything is done.

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

Sidebar

Related Questions

I am new to java.util.concurrent package and wrote a simple method which fetches some
I have the following test code. import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.FutureTask; class MyTask
I'm new to the package java.util.concurrent . I've created the following program testing if
I'm experimenting Java Multi-Threading using synchronization on method comparing with Atomic variables (java.util.concurrent.atomic package).
The following groovy script doesn't compile import java.util.concurrent.Callable println b; Callable<String> callable = new
I'm trying to test java.util.concurrent.ConcurrentLinkedQueue when accessed via multiple threads. Mentioned below is my
The javadoc for the java.util.concurrent.atomic package says the following: A small toolkit of classes
I have realized some logic using integers import java.util.concurrent.locks.*; public class MassageSalon implements Salon{
I have written the following code: import java.util.Calendar; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; class Voter
SimpleDateFormat formatter = new SimpleDateFormat(ddMMyyyy_HHmmSS); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = Cust_Advice_

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.