JavaBu+中的DocumentBuilderFactory是否是线程安全的? [英] Is DocumentBuilderFactory thread-safe in Java 5+?

查看:559
本文介绍了JavaBu+中的DocumentBuilderFactory是否是线程安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 1.4 doc for javax.xml.parsers.DocumentBuilderFactory 毫无疑问地说明:

The Java 1.4 doc for javax.xml.parsers.DocumentBuilderFactory states in no uncertain terms:


不保证DocumentBuilderFactory类的实现是线程安全的。用户应用程序要确保从多个线程中使用DocumentBuilderFactory。或者,应用程序可以为每个线程提供一个DocumentBuilderFactory实例。应用程序可以使用工厂的同一实例来获取DocumentBuilder的一个或多个实例,前提是工厂的实例一次不在多个线程中使用。

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 5 然而,Java 6 文档并没有说明这种情况。是 DocumentBuilderFactory 现在是线程安全的,还是Sun刚刚决定警告是否过度,人们应该知道更好?

The Java 5 and Java 6 docs, however, say nothing of the kind. Is DocumentBuilderFactory thread-safe now, or did Sun just decide the warning was overkill and people should know better?

推荐答案

因为在没有告诉我的钱的情况下使它保持线程安全,它仍然是非常糟糕的味道,它仍然是不安全的。您可以使用断点自行测试。

Since it would've been in extremely poor taste to make it thread safe without telling my money is that it's still unsafe. You can test this yourself using breakpoints.

这篇关于JavaBu+中的DocumentBuilderFactory是否是线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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