gpt4 book ai didi

java - DocumentBuilderFactory 在 Java 5+ 中是线程安全的吗?

转载 作者:太空狗 更新时间:2023-10-29 22:36:00 26 4
gpt4 key购买 nike

Java 1.4 doc对于 javax.xml.parsers.DocumentBuilderFactory 明确指出:

An implementation of the DocumentBuilderFactory class is NOT guaranteed to be thread safe. It is up to the user application to make sure about the use of the DocumentBuilderFactory from more than one thread. Alternatively the application can have one instance of the DocumentBuilderFactory per thread. An application can use the same instance of the factory to obtain one or more instances of the DocumentBuilder provided the instance of the factory isn't being used in more than one thread at a time.

Java 5Java 6然而,文档并没有说这种话。 DocumentBuilderFactory 现在是线程安全的,还是 Sun 只是认为警告是过度的,人们应该更好地了解?

最佳答案

根据单例的文档DocumentBuilderFactory newInstance 方法未同步 然后,DocumentBuilderFactory 在 Java 8 中仍然不是线程安全的...在 Java 11 中都不是.实际上,自 Java 1.4 以来,构造函数并没有改变。

关于java - DocumentBuilderFactory 在 Java 5+ 中是线程安全的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9828254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com