首页 > 解决方案 > 如何一次运行 2 个特定线程?像 platform.runLater() 和其他一些线程

问题描述

我的线程方法看起来像,

public void run(){
    int loop=100;
    int time=5;
    long StartTime = System.currentTimeMillis() / 1000;
    for(int i=0;i<loop;i++){
    Platform.runLater(new Runnable() { 
    @Override
    public void run() { 
    r2.setWidth(r2.getWidth()+1);
    }
    });
    try{
    Thread.sleep(100);
    if((time < ((System.currentTimeMillis() / 1000) - StartTime)))
        loop=0;
    }
    catch(Exception e){

    }
    }
}

在我的代码的某个地方,我创建了如下线程。

CustomThread thread[]=new CustomThread[3];
double len[]={30,60,90};
for(int i=0;i<thread.length;i++){
    thread[i]=new CustomThread(len[i]);
    thread[i].start();
/*  try{
    thread[i].join();
    }
    catch(Exception e){}*/
}

我希望线程[i] 完成它的执行,然后其他线程[i+1] 将完成它的执行。通过线程[i].join(); 我希望其他线程停止执行此线程,除了 platform.runLater() 线程,当我调用 join() 时该线程停止。总体而言,我希望 platform.runLater() 与当前线程连续执行。有什么建议么 ?

标签: javajavafx

解决方案


推荐阅读