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

  • Home
  • SEARCH
  • 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 7557417
In Process

The Archive Base Latest Questions

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

In my program I wrote a class, which updates a bunch of listeners every

  • 0

In my program I wrote a class, which updates a bunch of listeners every time when a new value is triggered. Therefor I am using a SingleThreadExecutor, the example should make it more clear. What I am worrying about is, does it make sense when I run it like that:

Class Update() {
    ExecutorService svc = Executors.newSingleThreadExecutor();

    svc.execute(new Runnable() {
        public void run() {
            if(!theListeners.isEmpty()) {
                for(IgpsdListener l : theListeners) {
                    l.update(jsonObject);
                }   
            }
        }
    });

I heard, that creating Threads is quite expensive action in JAVA, so I am wondering if I am using it correctly. I mean, it creates every time a new Runnable object right? Even the Executor uses only the one and only thread.

Thanks in advance for any help and enlightenment.
nyyrikki

  • 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-30T12:07:34+00:00Added an answer on May 30, 2026 at 12:07 pm

    This is exactly what you’re supposed to be doing. Java is quite fast at creating one-shot objects like this; threads might be expensive, but just creating a Runnable like you do here is cheap.

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

Sidebar

Related Questions

I wrote a program in C++/OpenGL (using Dev-C++ compiler) for my calculus 2 class.
I wrote the following program #include <iostream> template<typename C, typename Res, typename... Args> class
I wrote a program which includes writing and reading from database. When I run
I started a little experiment today: I wrote a C++ class which depends on
I wrote a program out, which was all in one file, and the methods
I wrote a class in charge of keeping track of error messages, which uses
I wrote a simple program with java swing which suppose to start another thread
I am using the following program to update the data which is stored in
I wrote a C++ DLL using VS 2010 which is used to wrap some
In my assembly language class, our first assignment was to write a program to

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.