0

A级

public Data getData(final String id){

   if(notAvailable(id)){

      classB.doSomethingAsync();
      throw new NotAvailableException();

   }
   else {
       return getData(id);
   }
}

B类

@Async
public void doSomethingAsync()
{
   int count = 100;
   while (count > 0)
   {
      count--;
      System.out.println(times);
      try
      {
         Thread.sleep(5000); 
      }
      catch (final InterruptedException e)
      {
         System.out.println("Sleep interrupted. Exiting");
         return;
      }
   }
}

假设所有这些都在网络应用程序中运行。发出请求并调用 ClassA.getData() 方法。代码路径遵循 notAvailable() 返回 true 的情况,我们调用 ClassB.doSomethingAsync() 并从 ClassA 向客户端抛出异常。

我的问题是,当 web 应用程序关闭时,B 类中的 while 循环是否会提前退出而不等待计数达到零?

我在测试过程中看到的结果好坏参半,我希望有人对发生的事情给出明确的答案。该应用程序在 Jetty 下运行。

4

0 回答 0