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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:19:07+00:00 2026-05-30T20:19:07+00:00

This will be my first multi threaded application if it can be developed as

  • 0

This will be my first multi threaded application if it can be developed as so. So I need some help getting started.

I currently have the following JAVA program that works perfectly well

  1. Get data from a source database and convert them to objects(POJOs)
  2. Get data from a target database and convert them to objects(POJOs).
  3. Compare both the source and target objects and if there is a difference, then update the target database with info from source database.

Now my requirement has changed and I need to use 3 different target databases(TargetDB1, TargetDB2, TargetDB3). Each one has a different connection info.

My question is , Can we make this a multi threaded application where in

Thread 1 will get source object

Thread 2 will get TargetDB1 object, compare to the source object(obtained from Thread 1) and update the TargetDB1 in case of differences with the source object

Thread 3 will get TargetDB2 object, compare to the source object(obtained from Thread 1) and update the TargetDB2 in case of differences with the source object

Thread 4 will get TargetDB2 object, compare to the sourceobject (obtained from Thread 1) and update the TargetDB2 in case of differences with the source object

If this can be developed as a multi threaded application, then how to go about it.

  • 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-30T20:19:08+00:00Added an answer on May 30, 2026 at 8:19 pm

    I would create a work queue for each of your target databases using some BlockingQueue such as a LinkedBlockingQueue. The producer thread will get the object from the source database and then add it to each of the work queues. Then each of the threads attached to a target database can dequeue from its work queue and update its database at its own speed.

    Source database thread might look something like:

    // allow only 10 outstanding objects to be in the work queue before it blocks
    queue1 = new LinkedBlockingQueue<SourceObject>(10);
    new Thread(new TargetDatabaseThread("url-to-database1", queue1)).start();
    queue2 = new LinkedBlockingQueue<SourceObject>(10);
    new Thread(new TargetDatabaseThread("url-to-database2", queue2)).start();
    queue3 = new LinkedBlockingQueue<SourceObject>(10);
    new Thread(new TargetDatabaseThread("url-to-database3", queue3)).start();
    while (true) {
        SourceObject sourceObj = getFromSourceDatabase();
        // this might block if you set a capacity on your queue and it was full
        queue1.put(sourceObj);
        queue2.put(sourceObj);
        queue3.put(sourceObj);
    }
    

    Each of the target database threads then might look like:

    public class TargetDatabaseThread implements Runnable {
        private final String jdbcUrl;
        private final BlockingQueue queue;
        private volatile boolean shutdown;
        public TargetDatabaseThread(String jdbcUrl, BlockingQueue queue) {
            this.jdbcUrl = jdbcUrl;
            this.queue = queue;
        }
        public void run() {
            // maybe some initialization, make database connection, etc.
            while (!shutdown) {
                // this would block if nothing is in the queue
                SourceObject sourceObj = queue.take();
                SourceObject targetObj =
                    getObjectFromTargetDatabase(sourceObj.getId());
                if (updateTarget(sourceObj, targetObj)) {
                   updateMyTargetObjectInDatabase(targetObj);
                }
            }
        }
    }
    

    One problem with this model would be if the target database threads need to update the source object in any manner. If this is the case then you would have to synchronize the object.

    Note that blocking queues can be set with a capacity. This would be useful in case it was easier for the producer to read from the source database than it was for the target database writers to update their databases. You wouldn’t want the queue to fill memory because the target databases are slow.

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

Sidebar

Related Questions

I currently debug a multi threaded application, which runs without errors until some functions
I am working on a multi-threaded application. This application started out as a single
I am writing a multi-threaded .Net application in which many callers need to concurrently
In my multi-threaded project(C# 3.5), I have many codes simliar to this: Map map;
So I have a multi-dimensional array looks like this. $config = array( First Name
I'm currently developing a heavily multi-threaded application, dealing with lots of small data batch
I have this code will work in multithreaded application. I know that immutable object
I know one awkward solution for this taks will be : first use ct
So this question will get technical – eventually – but first check out Hanselminutes
This will hopefully be an easy one. I have an F# project (latest F#

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.