Thread t1= new Thread(new Runnable() {
public void run() {
//perform Database stuff
}
});
t1.start();
initCache();//perform other Database stuff (Can this code be executed while thread 1 is running?)
如何确保 initCache 方法在 t1 完成后强制等待?
最佳答案
一开始不要在不同的线程中运行它?
您可以调用t1.join()
,但实际上,如果您想先运行任务 X,然后再运行任务 Y,只需在同一个线程中运行它们...
关于java - 与线程的可变干扰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5165994/