62,614
社区成员
发帖
与我相关
我的任务
分享
有一个方法
public boolean Login(){
Thread t1 = new Thread();
Thread t2 = new Thread();
t1.start();
t2.start();
return true;
}
如何在t1,t2运行结束后,再执行return true;这句
public boolean Login() {
Thread t1 = new Thread();
Thread t2 = new Thread();
t1.start();
t2.start();
try {
t1.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
t2.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
CyclicBarrier barrier=new CyclicBarrier(n, new Runnable(){//n表示有几个线程
public void run(){
//所有线程执行完,然后进行处理
}
});
public boolean login(){
Thread t1 = new Thread();
Thread t2 = new Thread();
t1.start();
t2.start();
while(t1.isAlive() || t2.isAlive()){
}
return true;
}
public boolean Login(){
Thread t1 = new Thread();
Thread t2 = new Thread();
t1.start();
t2.start();
boolean isRuning = true;
while (isRuning) {
if (t1.isAlive() || t2.isAlive()) {
isRuning = true;
}else {
isRuning = false;
}
}
return true;
}