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

The Archive Base Latest Questions

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

Is there a better way to do this? I would rather use an existing

  • 0

Is there a better way to do this? I would rather use an existing framework from j.u.c instead of rolling my own….

Please look at the “run” method.

I need to resubmit the Callable as soon as a result is obtained from the Future.
I’m using this separate Runnable Thread, just to do exactly this, as shown below.

Though this should compile, its obviously not a working piece of code..

public class ResubmitOnCompletion implements Runnable {

    private CompletionService<DeviceData> completionService;

    private ConcurrentHashMap<String, Device> devices;

    public void run() {

      //-- keep resubmitting the callable.
      while(true){


        try {
          //-- Get the returned data from completed job
          Future<DeviceData> f=null;
          DeviceData dd=null;

          f = completionService.take();

          //-- Get the completed job's data 
          dd=f.get();

          //-- now resubmit the job if device still is part of the active device collection
          completionService.submit((Callable<DeviceData>) devices.get(dd.getDeviceId()));
      }
      catch (CancellationException e) {
        e.printStackTrace();
      }
      catch (InterruptedException e) {
        e.printStackTrace();
      } catch (ExecutionException e) {
        e.printStackTrace();
      }         
    }   
  }


    //-- Device Data
    private class DeviceData {
      /**
       * Unique Device Identifier
       */
      private final String deviceId;

      /**
       * Holds all numeric data of the device.
       * Key=Variable id of the parameter
       * Value=Numeric value of the parameter
       */
      private final ConcurrentHashMap<String, BigDecimal> numericData;



      private DeviceData(String deviceId,
          ConcurrentHashMap<String, BigDecimal> numericData) {
        super();
        this.deviceId = deviceId;
        this.numericData = numericData;
      }


      /**
       * @return the deviceId
       */
      public String getDeviceId() {
        return deviceId;
      }

      /**
       * @return the numericData
       */
      public ConcurrentHashMap<String, BigDecimal> getNumericData() {
        return numericData;
      }
    }   

    //-- Device
    private class Device {
      public DeviceData call() throws Exception {
        return new DeviceData("",new ConcurrentHashMap<String, BigDecimal>());
      }

    }
}
  • 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:38:15+00:00Added an answer on May 23, 2026 at 4:38 pm

    You can simply submit the Runnable and within the run re submit itself

    ExecutorService e = Executors.newFixedThreadPool(1);
    
    private void submitWork(){
       e.submit(new Runnable(){
           public void run(){
              ///do work with devices and get its data            
              e.submit(this);
           }
       });
    }
    

    I am unsure why this would not work.

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

Sidebar

Related Questions

Is there a better way of doing this ? SELECT (SELECT count(*) FROM `tbl`
Is there a better way than this to splice an array into another array
Is there a better way than this to determine the row a user double-clicked
Is there a better way to do this? -(NSDate *)getMidnightTommorow { NSCalendarDate *now =
Is there a better way to write this code? I want to show a
Is there a better way to do this? string[] s = {zero, one, two,
Is there a better way of getting this result? This function fails if num
Is there a better way to do this? I have an HTML helper extension
Is there a better way to do this jquery code? Currently I have to
Is there any better way to make this query work? I'm looking for a

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.