在Scala中,是否有办法告诉您正在哪个执行上下文中运行? [英] In Scala, is there a way to tell which execution context you are running in?

查看:78
本文介绍了在Scala中,是否有办法告诉您正在哪个执行上下文中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Scala中,如果我知道一段代码正在Future中运行,是否有办法找出Future驻留在哪个ExecutionContext中?例如,以便我可以将此信息写到日志中。

In Scala, if I know that a piece of code is running in a Future, is there a way of finding out in which ExecutionContext the Future resides? E.g., so that I can write out this information to a log.

别担心,我不想做任何邪恶的事情。我只想要调试信息。

Don't worry, I don't want to do anything nefarious. I just want the information for debugging.

推荐答案

维克多·巴生(Viktor Klang)在评论中说:

Viktor Klang had this to say in a comment:


任何明智的ExecutionContext应该适当地命名其线程,
然后使用Thread.currentThread()。getName()在日志中显示。

Any sensible ExecutionContext ought to name its threads appropriately, then it shows up in logs using Thread.currentThread().getName().

我认为这正是我所需要的。

I think that this is just what I need.

谢谢,维克多!

这篇关于在Scala中,是否有办法告诉您正在哪个执行上下文中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆