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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:53:20+00:00 2026-05-25T10:53:20+00:00

this is the code i have (sort of) foo(a, b) { c = a.item;

  • 0

this is the code i have (sort of)

foo(a, b)
{
    c = a.item;

    bar(c);
    b = a;
    b.count--;
}

i want bar(c) to run in a separate thread.
So far this is what i have:
i make the class implement runnable.
I replace the bar(c) line with t = new Thread(this, "Demo Thread"); t.start();
and i create a function later in the code that looks like this:

public void run
{
    bar(c);
}

the problem is that i dont know how to get c into run. can anyone explain how i can do this ?

  • 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-25T10:53:20+00:00Added an answer on May 25, 2026 at 10:53 am

    I modified your code to run bar(c) in its own thread.

    foo(a, b)
    {
        final c = a.item;
        new Thread() { 
            @Override
            public void run() {
                bar(c);
            }
        }.start();
        b = a;
        b.count--;
    }
    

    Essentially what you are doing is creating a new Thread object that will just make the call to bar(c). You also need to make c final in the method so you are allowed to pass it into the run method of the anonymous inner class.

    I would also like to note that using this method, the Thread that runs bar just goes off on its merry way and you have no way to monitor its progress. You may want to add some more robust logic to handle the flow of the program. (If it’s needed.)

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

Sidebar

Related Questions

So I have this code for these Constructors of the Weapon class: Weapon(const WeaponsDB
I have some code that does something like this (Irrelevant bits snipped): void foo(Bitmap
I have the following code: class Foo { public Foo() { Size = true;
This is a learning exercise in expression trees. I have this working code: class
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"]
So I have this code that takes care of command acknowledgment from remote computers,
So I have this code in a google app engine template: <select name='voter'> {%
Hey I have this code right here: http://pastie.org/534470 And on line 109 I get
Imagine I have this code: var myFunc1 = function(event) { alert(1); } var myFunc2

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.