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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:08:14+00:00 2026-05-19T04:08:14+00:00

Say for example that I have a Runnable called RunnableA that does something. I

  • 0

Say for example that I have a Runnable called RunnableA that does something. I also have a Runnable called RunnableB that does something else. Is there a way that I can combine these two Runnables someway so that they will run in the same thread?

The second part of the question is if this is possible, can I then specify the order that they will run in?

EDIT!: The reason why I wanted to do this was because I need to run code on the EDT but some of the other code needs to be run on another thread. Please take a look at the code below.

Something like this


public final class CompoundRunnable implements Runnable
{
    private final Iterable runnables;

    public CompoundRunnable(Iterable runnables)
    {
        // From Guava. Easy enough to do by hand if necessary
        this.runnables = Lists.newArrayList(runnables);

    }

    public CompoundRunnable(Runnable... runnables)
    {
        this(Arrays.asList(runnables));
    }

    @Override
    public void run()
    {
        for (Runnable runnable : runnables)
        {
             runnable.run();
        }
    }
}


public void setStatusAndProgress(final String status,Runnable runnable)
    {
        Runnable startUpRunner = new Runnable()
        {
            public void run()
            {
                SwingUtilities.invokeLater(new Runnable()
                {
                    public void run()
                    {
                        setStatus(status);
                        selfReference.getProgressBar().setIndeterminate(true);
                    }

                });
            }
        };
        Runnable cleanUpRunner = new Runnable()
        {
            public void run()
            {
                SwingUtilities.invokeLater(new Runnable()
                {
                    public void run()
                    {
                        setStatus("");
                        getProgressBar().setIndeterminate(false);
                    }
                });
            }
        };

        Runnable theRunner = new CompoundRunnable(startUpRunner,runnable,cleanUpRunner);
        new Thread(theRunner).start();
    }

Sorry if this isnt explained well, post comments if you need clarification.

Thanks!

  • 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-19T04:08:15+00:00Added an answer on May 19, 2026 at 4:08 am

    Well you can certainly create a Runnable which just runs one runnable then the other:

    public final class CompoundRunnable implements Runnable
    {
        private final Runnable first;
        private final Runnable second;
    
        public CompoundRunnable(Runnable first, Runnable second)
        {
            this.first = first;
            this.second = second;
        }
    
        @Override
        public void run()
        {
            first.run();
            second.run();
        }
    }
    

    More generally, you could make it take an Iterable<Runnable>, copy all the Runnable references, and then run them in order. For example:

    public final class CompoundRunnable implements Runnable
    {
        private final Iterable<Runnable> runnables;
    
        public CompoundRunnable(Iterable<Runnable> runnables)
        {
            // From Guava. Easy enough to do by hand if necessary
            this.runnables = Lists.newArrayList(runnables);
        }
    
        public CompoundRunnable(Runnable... runnables)
        {
            this(Arrays.asList(runnables));
        }
    
        @Override
        public void run()
        {
            for (Runnable runnable : runnables)
            {
                 runnable.run();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example: First, say I have a Silverlight app with Windowless=true so that I
Say for example you're getting a web app project that interacts with a database.
Here is my scenario. For the example lets say that I need to return
I want to add items in a LaTeX-document. Say for example, that I want
For Example: Let's say that I want to return a view that displays a
My simplified and contrived example is the following:- Lets say that I want to
Say for example I have the following string: var testString = Hello, world; And
I have a webpage (say www.example.com/a.asp) .. I am having an iframe in this
An instance of class A instantiates a couple of other objects, say for example
How would I run both of them under one main website, say www.example.com, which

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.