Okay so right now I have essentially this code:
class a {
public void ab() {
b thread = new b();
thread.bb(this);
}
}
class b {
public void bb(a _a) {
//execute code here in new thread so ab can continue running
}
}
However this doesn’t open it in a new thread, and yes I did research this, all the solutions I found didn’t leave any option to send a parameter (this) to the bb method
How to call class.method in new thread that requires a parameter?
To start a thread, you must have an instance of
java.lang.Thread, of whichbis not. You can extend thread to achieve this.A Thread runs asynchronously whatever you place in its
run()method, which you can override from its original (empty) implementation.However, this doesn’t allow you to pass an instance of
a. Your best option here is to take an instance ofaas an instance variable in the constructor ofb.Finally, to run the thread asynchronously, you don’t call the newly implemented
run()method, but you callThread#start(), which invokes therun()method in a new thread.As a side note, standard Java convention is to start class names with capital letters, so you should rename
atoAand so forth. This however won’t make any difference as far as compilation or execution goes.