java - AWS Lambda - 如果我启动一个线程,当 Lambda 卡住/解冻时会发生什么?

标签 java multithreading amazon-web-services aws-lambda

我有一个启动后台线程的基于 Java 的 AWS Lambda 函数。该线程运行一个计划任务,该任务向外部服务报告指标。

根据 the Lambda docs ,Lambda 函数在完成执行后会“卡住”一段时间,然后可以“解冻”并重新使用 if the function is triggered again在短期内。

我的问题是发生这种情况时后台线程会发生什么。例如,我在包含我的处理程序函数的类的构造函数中启动了我的后台线程。根据文档,处理函数范围之外的所有变量都将保持初始化状态,所以我的线程应该仍然存在,但它还会运行吗?我的线程在后台运行这一事实会阻止 Lambda 首先完成执行吗?或者它是否会超过五分钟的限制,因为它还没有完全完成,即使处理函数已经完成?

最佳答案

这在 AWS 官方博客中得到解决 here :

But let’s say you have a background process running when the function finishes – what happens to it if the container is reused? In this case, Lambda will actually “freeze” the process and thaw it out the next time you call the function (but only if the container is reused, which isn’t a guarantee). So in the reuse case, your background processes will still be there, but they won’t have been executing while you were away.

关于java - AWS Lambda - 如果我启动一个线程,当 Lambda 卡住/解冻时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39667336/

相关文章:

java - 如何创建递归方法来生成二叉树?

java - 不必要的 Java 上下文切换

android - 关于线程和延迟时间

windows - Goroutines 8kb 和 windows 操作系统线程 1 mb

amazon-web-services - 报告是否使用 aws cli 启用了 Performance Insights

django - AWS ElasticBeanstalk : JWT token not being validated after configuration change

java - 如何为 scalatest-maven-plugin 设置 PermSize?

Java - 调用静态方法与手动内联 - 性能开销

java - Java:存储随机种子以通过线程进行复制

amazon-web-services - EC2 UserData 脚本在启动时未运行