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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:59:32+00:00 2026-05-15T00:59:32+00:00

I have a callback which receives an object. I make a copy of this

  • 0

I have a callback which receives an object. I make a copy of this object, and I must pass it on to another thread for further processing. It’s very important for the callback to return as fast as possible. Ideally, the callback will write the copy to some sort of lock-free container.

I only have the callback called from a single thread and one processing thread.

I only need to pass a bunch of doubles to the other thread, and I know the maximum number of doubles (around 40).

Any ideas? I’m not very familiar with Java, so I don’t know the usual ways to pass stuff between threads.

  • 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-15T00:59:33+00:00Added an answer on May 15, 2026 at 12:59 am

    If this is just a one-off thing – you get the 40- or so doubles, and want to start a new thread processing that, then you can do it like this:

    public void callback(final double[] myDoubles)
    {
      new Thread(){
       public void run() {
          // you can use myDoubles here. it will run on a separate thread.
       }}.start()   
    };
    

    If this is something that happens often, then you will need to look into thread pools and use a java.utils.concurrent.BlockingQueue. Despite the name, the queue will only block if it becomes full.

    You can create an array of doubles the appropriate size which your callback method puts into the queue. The put() operation is very quick and so your callback method will not be delayed for long. (unless the queue is full.)

    Your other thread will use the take() method on the queue to get the object when an object is available. The take() method blocks until an object is available – if you don’t want that, but prefer to keep the thread running, doing other things, then use poll() instead.

    One final thing to consider is – do you want just one worker thread handling the doubles from the callback, or do you want several? Having one thread makes sense when the work needs to be done one at a time – e.g. if you write the array to a file, there’s usually no point having multiple threads doing this. Buf if the work done on each array is independent, then it’s a good candidate for having multiple worker threads.

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

Sidebar

Related Questions

I have this static callback function in MyClass, and I try to call another
INTRODUCTION : I have a function(callback) that receives a object as an argument, inside
My question is about Javascript. I have a Callback function which receives a Position
I have Java application which sends pointer to function (callback) to some native dll
I have a js function which has, until now, always been the callback for
I have the following code, in which Boost.Local uses a function callback to load
Is there a way to have the callback of one AJAX trigger another AJAX
I have a Django view that receives POSTs which do not need to have
I have a dll which requires me to set a callback function for it
Lets say I have heap allocated A* , which I want to pass as

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.