I have a problem. I have 4 classes: classA
, classB
, classC
with all a function called run()
. Now I am trying to work with async, so what I want is the following:
- In my
MainClass
, I call a async function fromclassA
calledrun()
- At the end of
classA.run()
, I call aclassB.run()
- In my MainClass, I want to wait until
classA
andclassB
have printed their line before runningclassC.run()
.
Here is the code from every class. Class A:
public class classA {
public void run() {
System.out.println("CLASS A");
new classB().run();
}
}
Class B:
public class classB {
public void run() {
System.out.println("CLASS B");
}
}
Class C:
public class classC {
public void run() {
System.out.println("CLASS C");
}
}
And here is the code from my MainClass
:
public class MainClass {
public static void main(String[] args) {
CompletableFuture<Void> testRun = CompletableFuture.runAsync(() -> {
new classA().run();
});
CompletableFuture<Void> test2Run = CompletableFuture.completedFuture(testRun).thenRunAsync(() -> {
new classC().run();
});
}
}
But in my terminal I don't see any prints...
What am I doing wrong?