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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:46:51+00:00 2026-06-15T13:46:51+00:00

I am pretty new to multi threading and tried something to apply it, but

  • 0

I am pretty new to multi threading and tried something to apply it, but I am kinda stuck.

Here is the scenario:
using drools to apply rules on a set of objects read from the db, then write the updated values back to the db.

Now, I repeat the above process multiple times, so i want to run the reading+drool process in one thread(main thread) and the writing part in another.

So I write the below code:

Thread thread = new Thread(new Runnable() 
{     public void run()
    { 
         try 
         {
    //writing the updated data in DB    
    aggregationDAO.updateCaseDetailsInOracle(queryList);
    } 
         catch (Exception e) {                              throw new RuntimeException();
    }
   }
});
    thread.start();

But, I am stuck here.

Firstly, it expects my queryList to be final.

I cannot make it final coz every time new updated data loads in the same variable.

Secondly,

even after making my program run multi threads, there is no improvement in my run time.

Can, someone tell me where I am getting wrong?

  • 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-06-15T13:46:52+00:00Added an answer on June 15, 2026 at 1:46 pm

    You just use your custom thread instead of ‘main’, so there is no improvment. There is no ‘multi’ threading in your example.

    If you want to see speed improvment, you should run several thread simultaniously.
    Use some sort of thread pool for concurrent task processing, and then you will get improvment.

    Also, variable must be final, because you are creating anonymous class – Runnable. You should create new class wich will implements Runnable and pass into constructor your variable.

    class QueryTask implements Runnable {
        private final List queryList;
        public QueryTask(List queryList) {
            this.queryList = queryList;
        }
    
        @Override
        public void run() {
            try { //writing the updated data in DB
                aggregationDAO.updateCaseDetailsInOracle(queryList);
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
    

    USAGE:

    final ExecutorService threadPool = Executors.newCachedThreadPool();
    threadPool.submit(new QueryTask(queryList.subList(0, 5)));
    threadPool.submit(new QueryTask(queryList.subList(6, 10)));
    

    This will process your queryList by portions concurrently.

    UPDATE:

    When you already submit all your tasks, you can shutdown threadPool and wait while all tasks will be done.
    You can not add any new task after that.

        threadPool.shutdown();
        try {
            threadPool.awaitTermination(10, TimeUnit.MINUTES);
        } catch (InterruptedException e) {               
            // Current thread was interrupted.
            final List<Runnable> runnables = threadPool.shutdownNow();
            System.out.println("Can't stop tasks: " + runnables.size());
    
            // Restore interrupted status.
            Thread.currentThread().interrupt();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty new to multi-threading in general and I would like to know
Possible Duplicate: C# Captured Variable In Loop I am pretty new to multi-threading programming.
My multi-threading knowledge is still pretty rudimentary, so would really appreciate some pointers here.
My question might sound a bit naive but I'm pretty new with multi-threaded programming.
Pretty new to Perl so there may be a very obvious solution here. I'm
Im pretty new to Java Web Services, but I cant find a good explanation
I'm pretty new to PHP, but I decided to try and make a simple
I am pretty new to buddypress. I am trying to do something pretty simple
I am updating a multi select box using ajax with prototype: new Ajax.Updater(selectbox, someurl,{
Pretty new to jquery but i was hoping to be able to target 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.