Java 倒计时闩锁在web应用程序中有多有用?我们能得到一个实时场景吗?

Java 倒计时闩锁在web应用程序中有多有用?我们能得到一个实时场景吗?,java,Java,倒计时闩锁在web应用程序中如何有用?有人能解释一个实时场景吗 public class CountDownLatchTest { public static void main(String[] args) { CountDownLatch cdlatch=new CountDownLatch(5); new Event(cdlatch); try { cdlatch.await(); } catch (InterruptedExceptio

倒计时闩锁在web应用程序中如何有用?有人能解释一个实时场景吗

public class CountDownLatchTest {

public static void main(String[] args) {
    CountDownLatch cdlatch=new CountDownLatch(5);
    new Event(cdlatch);

    try {
        cdlatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    System.out.println("event executed done!");

}

}

public class Event implements Runnable{

CountDownLatch cdlatch;

public Event(CountDownLatch cdlatch) {
    new Thread(this).start();
    this.cdlatch=cdlatch;
}

@Override
public void run() {
    for(int i=0;i<20;i++){
        System.out.println("event "+i);
        cdlatch.countDown();
    }

}

}
公共类倒计时测试{
公共静态void main(字符串[]args){
CountDownLatch cdlatch=新的CountDownLatch(5);
新事件(cdlatch);
试一试{
cdlatch.await();
}捕捉(中断异常e){
e、 printStackTrace();
}
System.out.println(“事件执行完毕!”);
}
}
公共类事件实现可运行{
倒计时锁存器;
公共事件(倒计时闩锁cdlatch){
新线程(this.start();
this.cdlatch=cdlatch;
}
@凌驾
公开募捐{
对于(int i=0;i
有人能解释一个实时场景吗

public class CountDownLatchTest {

public static void main(String[] args) {
    CountDownLatch cdlatch=new CountDownLatch(5);
    new Event(cdlatch);

    try {
        cdlatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    System.out.println("event executed done!");

}

}

public class Event implements Runnable{

CountDownLatch cdlatch;

public Event(CountDownLatch cdlatch) {
    new Thread(this).start();
    this.cdlatch=cdlatch;
}

@Override
public void run() {
    for(int i=0;i<20;i++){
        System.out.println("event "+i);
        cdlatch.countDown();
    }

}

}
请考虑您的web应用程序不应提供任何请求,直到:

  • 您可以缓存来自DB或任何外部实体的一些数据
  • 您的所有工作线程都已启动并准备好为请求提供服务

完成后,只有您可以开始处理请求。在这种情况下,如果您在缓存数据之前开始处理请求,那么您可能会使用空数据处理请求。

在web应用程序中,我有一个页面,作为余额信息和事务。如果我只想在余额信息事件为co时加载页面完成后,我处理事务,然后显示页面。在这里是否可以工作?请解释?