您可以尝试这样做:
public class B{
private boolean c;
volatile boolean finished = false;
BufferedImage output;
public B (boolean c_) { c = c_;}
public void process() {
Thread t = new Thread(new Runnable(){
@Override
public void run() {
if (c) output = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
finished = true;
}
});
t.start();
}
}
public class A {
public void compute() {
B b = new B(true);
b.process();
while(!b.finished){System.out.println("Processing");}
// when finished check if output is not null
// and then do some stuff
if(b.output!=null){System.out.println(b.output);}
}
}