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 ?
I modified your code to run
bar(c)in its own thread.Essentially what you are doing is creating a new
Threadobject that will just make the call tobar(c). You also need to makecfinal in the method so you are allowed to pass it into therunmethod of the anonymous inner class.I would also like to note that using this method, the
Threadthat runsbarjust 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.)