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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:15:33+00:00 2026-06-06T02:15:33+00:00

In Java I have the necessity of implementing a class that extends Thread within

  • 0

In Java I have the necessity of implementing a class that extends Thread
within another similar class. Is that possible?

An example of what I am trying to do is the following (simplified) snippet:

// The first layer is a Thread
public class Consumer extends Thread {

    // Variables initialized correctly in the Creator
    private BufferManager BProducer = null;

    static class Mutex extends Object {}
    static private Mutex sharedMutex = null;


    public Consumer() {
        // Initialization of the thread
        sharedMutex = new Mutex();

        BProducer = new BProducer(sharedMutex);
        BProducer.start();
    }


    public void run() {

        int data = BProducer.getData();

        ///// .... other operations
    }


    ////// ...... some code

    // Also the second layer is a Thread
    private class BufferManager extends Thread {

        Mutex sharedMutex;
        int data;

        public BufferManager(Mutex sM) {
            sharedMutex = sM;
        }

        public int getData(Mutex sM) {
            int tempdata;
            synchronized(sharedMutex) {
                tempdata = data;
            }
            return tempdata;
        }

        public void run() {
            synchronized(sharedMutex) {
                data = getDataFromSource();
            }
            ///// .... other operations on the data
        }
    }
}

The second Thread is implemented directly inside the First one.
Moreover I’d like to know if implementing a Mutex like that will work.
If not, there’s any better (standard) way to do it?

Thank you in advance.

  • 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-06T02:15:36+00:00Added an answer on June 6, 2026 at 2:15 am

    The Thread is not run ‘within’, but rather side-by-side.

    So yes, you can start up another Thread to run side-by-side with your other two Thread‘s. As a matter of fact, any Thread can start another Thread (so long as the OS allows it).

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

Sidebar

Related Questions

I am new to Java. I just read that class variables in Java have
The scenario is the following: I have a java package ( myapp.config ) that
I have a Java class that pertains to mouse listeners that I'm wanting to
I have a java class that prints thousands of lines on the System.out. I
Does Java have (or is there a library available) that allows me to have
I know that Java have its own garbage collection, but sometimes I want to
I'm an experienced Java programmer that for the last two years have programmed for
I have java application that sending( HTTP post method ) credit card numbers to
I have a java program that I am running inside of a command prompt
What would be a good way to dynamically load java class files so that

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.