.net - XslCompiledTransform 线程安全

标签 .net multithreading xslcompiledtransform

MSDN for .NET System.Xml.Xsl.XslCompiledTransform 类状态:

Thread Safety

[1] The XslCompiledTransform object is thread safe once it has been loaded. In other words, after the Load method has successfully completed, the Transform method can be called simultaneously from multiple threads.

[2] If the Load method is called again in one thread while the Transform method is being called in another thread, the XslCompiledTransform object finishes executing the Transform call by continuing to use the old state. The new state is used when the Load method successfully completes.

[3] Note The Load method is not thread safe when called simultaneously from multiple threads.

我(相当)确定段落 [1][2] 指的是 Load()/Transform ()相同 XslCompiledTransform 对象实例上被调用(在多个线程中)。但是对于 [3],有没有人知道它们是指同时 Load()same 实例上,还是(有一些静态的东西)这意味着)您必须从所有实例中相互排除并发Load()

最佳答案

查看 ILSpy 中的代码,没有可见的静态同步构造。您可以在不同线程的不同实例上调用 Load()

可以预见,Load 将实例化一个 XSLT 编译器并将样式表编译为一个内部对象,该对象稍后将由 Transform 方法使用。这解释了 [1]:一旦转换被编译,它就可以从不同的线程调用,因为内部对象现在是只读的。

再次调用 Load 将重新编译内部对象,因此它必须与当前正在进行的任何转换同步,这占 [2]。

从不同的线程同时调用编译器会导致构建最终内部转换对象的竞争 ([3])。尽管不同的实例是独立的,但它们都有自己的内部转换对象,并且每次调用 Load 时都会实例化一个新的编译器。

关于.net - XslCompiledTransform 线程安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27316343/

相关文章:

c# - 在 tabcontainer 中启用 tabpanel

c# - 如何获取使用过的dll的版本

c# - 我如何充分了解 CLR 以对性能问题做出有根据的猜测?

java - 当 JDialog 可见时执行 SQL 语句?

c# - XslCompiledTransform 输出为 XPathDocument

c# - 是否有更有效的方法来转换已经包含对 XSLT 的引用的 XDocument?

c# - 有人可以解释测试驱动开发中的 "Fake it till you make it"方法吗?

c++ - 编译器在这里执行哪种循环优化?

java - 如果 Java 线程已经被该线程占用,为什么还必须重新进入该锁?

.NET 中的 xslt 解析