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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:47:11+00:00 2026-06-14T08:47:11+00:00

I am using ThreadPoolExecutor utility and passing the values thru constructor in called class.

  • 0

I am using ThreadPoolExecutor utility and passing the values thru constructor in called class. The constructor takes two arguments (1) a map (2) a string.

I am confused on how to declare a bean for the called class which takes two arguments( a map and a string). My code is as below.

***Calling Class***

    public class Starter {

        ProcessScheduler deleteBatch;
        public ProcessScheduler getDeleteBatch() {
            return deleteBatch;
            }

        public void setDeleteBatch(ProcessScheduler deleteBatch) {
            this.deleteBatch = deleteBatch;
            }


        public void start() {

        ThreadPoolExecutor executor = testThreadPoolExecutorService.createNewThreadPool();


            for (int i=0;i<=5;i++)
            {
            Map m4 = arrayRecords.get(i);
            executor.execute(new ProcessScheduler("Thread #"+i,m4));                     // Comment - started 
The above line executes fine but it gives null pointer error if I will call any other method from the run() inside  called class(ProcessScheduler). So I have use a Bean such as executor.execute(getDeleteBatch("Thread #"+i,m4)) to get the instance of the bean. But I dont know how to do this in this case?

// Comment - ended


            }

***Called Class***



public class ProcessScheduler implements Runnable {

         public ProcessScheduler(String taskName, Map m) {
            this.taskName = taskName;
            this.deleteRecordsMap = (HashMap) m;
            }
        Processor processor;
        public Processor getProcessor() 
        {
            return processor;
        }


        public void setProcessor(Processor mappProcessor) {
            this.mappProcessor = mappProcessor;
        }


        public void run() 
        {
        // This returns null 
        processor.getNumbers();
        }

        }



I have some confusions as below.
(1) How to declare a bean for ProcessScheduler in this case. 
(2) Is the declaration of getDeleteBatch is correct in this case like below?

public ProcessScheduler getDeleteBatch() {
            return deleteBatch;
            }

Thanks
Gendaful

  • 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-14T08:47:12+00:00Added an answer on June 14, 2026 at 8:47 am

    I have solved this issue as below,

    From my calling class, I am passing the instance of Processor class in the execute method.

    executor.execute
    (newProcessScheduler("Thread#"+Thread.currentThread().getName(),hm,processor))
    

    So, what it does is, since I am passing the processor as an argument in the execute(), it will not throw nullpointerexception if I call a method of processor inside run() of ProcessScheduler class.

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

Sidebar

Related Questions

I'm using concurrent.futures ' class ThreadPoolExecutor to do stress testing on a webservice. As
I've been messing around with different strategies for thread pooling using ThreadPoolExecutor with JDK6.
Using import datetime in python, is it possible to take a formatted time/date string
This is in an application I am using called Mirth, but it appears to
I am using the ThreadPoolExecutor to implement threading in my Java Application. I have
What is the best way to handle RejectedExecutionException while using a ThreadPoolExecutor in Java?
I am using an ExecutorService (a ThreadPoolExecutor) to run (and queue) a lot of
I am using ThreadPoolExecutor in my multithreading program, I want each thread should have
I'm using ThreadPoolExecutor in SomeService to perform some work on data. The problem is
I am trying to get a script performance improved, using ThreadPoolExecutor from concurrent.futures. I

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.