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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:33:49+00:00 2026-05-25T11:33:49+00:00

Many time-consuming threads (500-900ms.) are created in the application. They are to be executed

  • 0

Many time-consuming threads (500-900ms.) are created in the application.
They are to be executed in the order they have been created – one after another – not simultaneously. The execution should be processed in thread, that is not synchronized with main application thread.

I can’t make small threads executed in an order, so I found a ThreadPoolExecutor, but think it’s too heavy for my task. So I wrote my Executor class.

It works fine. You add a thread to the threadList and it start the Executor thread to execute small tasks, that can be added while execution.

Can you tell me it’s drawbacks and maybe another better way to solve my problem.

import java.util.LinkedList;
import java.util.List;

public class SfourExecutor extends Thread implements Runnable {

    private static List <Thread> threadList = new LinkedList<Thread>();
    private static final SfourExecutor INSTANCE = new SfourExecutor();

    public static List<Thread> getThreadList() {
        return threadList;
    }

    public static void setThreadList(List<Thread> threadList) {
        SfourExecutor.threadList = threadList;
    }

    public void addToThreadList(Thread thread) {
        getThreadList().add(thread);
        if (!this.isAlive()) {
            this.start();
        }
    }

    public static SfourExecutor getInstance() {
        return SfourExecutor.INSTANCE;
    }

    private static class SfourHolder {
        private static final SfourExecutor INSTANCE = new SfourExecutor();
    }

    SfourExecutor () {
    }


    @Override
    public void run() {
        LinkedList <Thread> tL = (LinkedList<Thread>) getThreadList();

        while (!tL.isEmpty()) {
            Thread t = tL.poll();
            if (t!=null) {
                t.start();
                try {
                    t.join();
                } catch (InterruptedException ex) {
                }
            }
        }
    }

}
  • 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-25T11:33:50+00:00Added an answer on May 25, 2026 at 11:33 am

    Won’t an Executor created via Executors.newSingleThreadExecutor() meet your requirements exactly? “Tasks are guaranteed to execute sequentially, and no more than one task will be active at any given time.”

    Don’t create new Thread instances when you don’t need to execute jobs concurrently. Even if you are working with legacy code that has implemented some logic in a Thread class, you should be able to execute them as Runnable instances to the executor.

    If you insist on using your own executor, you should know that your current implementation is not thread-safe. LinkedList is not a concurrent data structure, and since any code in the process can add new jobs at any time, you have no way to ensure that all jobs are added to the list before your executor thread is started. Thus, changes to the list are not guaranteed to be visible to all of the threads that are working with it.

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

Sidebar

Related Questions

I am working on a WPF application. I have a time consuming method that
While there are many guides for Browser Helper Objects, i have a hard time
I have an MDI parent form that creates many MDI children at run time.
I have a method which has been called many times by other methods to
I have created a pkg for my regular simple commands. They are non-static, to
I have a queue onto which pending fourier transform requests (comparatively time consuming operations)
I have many log files like this: ...... ...... cpu time 9.05 seconds real
I have many log files like this: ...... ...... cpu time 9.05 seconds real
Hi I have an application which after login, loads a main activity which contains
The first time I try to open a particular form many of the controls

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.