What are the correct ways/practice/implementation/strategies (or whatever we call it as) for not to wait for code block/method to finish execution in Java?
Assume the following method:
private void myMethod()
{
// Some lines of code here
.....
.....
.....
anotherMethod(); // or this could be a code block
// Again some lines of code here
.....
.....
.....
}
In this case, I expect myMethod()
should not wait for code to finish execution of anotherMethod()
. I can also assure here that subsequent lines of code do not depend on anything getting executed within anotherMethod()
.
You can start it in another Thread if there is no dependency .
new Thread(new Runnable(){
public void run(){
anotherMethod();
}
}).start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With