更新时间:2023-10-20 15:35:28
如果你想运行两个循环(或者更多)同时使用 Threads
。只需在一个线程中定义每个循环,然后启动你的主题:)
if you want to run two loops ( or more ) at the same time , use Threads
. just define each loop in one thread, and then start your threads :)
示例:
第一个帖子:
public class ThreadForLoopA extends Thread{
// variables for your Thread ...
@Override
public void run(){
// your first loop here ...
}
}
第二个帖子:
public class ThreadForLoopB extends Thread{
// variables for your Thread ...
@Override
public void run(){
// your second loop here ...
}
}
开始这样的所有主题:
ThreadForLoopA threadA = new ThreadForLoopA();
ThreadForLoopB threadB = new ThreadForLoopB();
//start threads (the two loops will be executed at the same time)
threadA.start();
threadB.start();