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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:28:46+00:00 2026-06-16T02:28:46+00:00

I want to initialize Synchronized static singleton ThreadPool Executor with my defined properties. I

  • 0

I want to initialize Synchronized static singleton ThreadPool Executor with my defined properties.

I want it to available through out the application and should be destroyed when server is restarted or stopped.

public class ThreadPoolExecutor extends java.util.concurrent.ThreadPoolExecutor {
    private static Properties properties;
    static {
        try {
            properties.load(ThreadPoolExecutor .class.getClassLoader().getResourceAsStream("config.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    static final int defaultCorePoolSize = Integer.valueOf((String) properties.get("CORE_POOL_SIZE"));
    static final int defaultMaximumPoolSize = Integer.valueOf((String) properties.get("MAX_POOL_SIZE"));
    static final long defaultKeepAliveTime = Integer.valueOf((String) properties.get("KEEP_ALIVE_TIME"));
    static final TimeUnit defaultTimeUnit = TimeUnit.MINUTES;
    static final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>();
    private static ThreadPoolExecutor instance;

    private ThreadPoolExecutor() {
        super(defaultCorePoolSize, defaultMaximumPoolSize, defaultKeepAliveTime, defaultTimeUnit, workQueue);
    }

    synchronized static ThreadPoolExecutor getInstance() {
        if (instance == null) {
            instance = new ThreadPoolExecutor();
        }
        return instance;
    }   

This is what I have done till now (I am newbie to Multi-threading).

As my application is completely based on Multi-threading, how do I achieve my requirements and anything to improve here!
As I said, how do i maintain/make it available through out the application.

  • 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-16T02:28:48+00:00Added an answer on June 16, 2026 at 2:28 am

    Use a class that implements ServletContextListener in your web.xml:

    <web-app>
        <!-- ... -->
        <listener>
            <listener-class>com.domain.ThreadPoolManager</listener-class>
        </listener>
    </web-app>
    

    The class ThreadPoolManager should override the methods contextInitilized(ServletContextEvent) and contextDestroyed(ServletContextEvent). The method contextInitilized(ServletContextEvent) gets invoked the web application initialization process is starting. So, you should do your initialization work there. Similarly, the method contextDestroyed(ServletContextEvent) gets invoked when the servlet context is about to be shut down. So, you should do your clean up work there.

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

Sidebar

Related Questions

I want to initialize a static Class variable in Java: public class NumberExpression {
Window c# Desktop Application I want to initialize a DataRow object with the selected
Stack Overflow. Let's say I want to initialize a non-static class of variables, two
I'm creating a ios application without nib files and want to initialize the window
I want to initialize a user configuration through a user configuration file. The path
I want to initialize two static data members. See the two files // Logger.h
I want to initialize JavaScript array value from c# in asp.net application. I have
I want to initialize a static field which I added to a class using
I want to initialize a static collection within my C# class - something like
When I want to initialize a pointer to an array through the function, 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.