简体   繁体   English

多程序读单 XML Java

[英]Many programs reading single XML Java

My program uses a SAX parser (or maybe DOM parser) to read from an XML file located somewhere on a server.我的程序使用 SAX 解析器(或者可能是 DOM 解析器)从位于服务器某处的 XML 文件中读取。 Now many people use my program, so many programs sometimes access this one XML file.现在很多人使用我的程序,所以很多程序有时会访问这个 XML 文件。 Can there be problems if eg two users (which are using my program at the same time) want to read (only read and not write) the XML file at the same time?例如,如果两个用户(同时使用我的程序)想同时读取(只读取而不是写入)XML 文件,会不会有问题? Do I have to consider anything special in my program or will this be handled by the OS?我是否必须在我的程序中考虑任何特别之处,或者这将由操作系统处理?

Unfortunately I am not familiar with simultaneous access to files or if several people use my program and such a siutation occurs.不幸的是,我不熟悉同时访问文件或者如果有几个人使用我的程序并且会发生这种情况。

The program is built with Java 11.该程序使用 Java 11 构建。

It shouldn't cause a problem.它不应该引起问题。 It's not necessarily the most efficient way of doing it but for a low-throughput application it should work perfectly well (we have an in-house application that handles about 10 requests per day and this is exactly how we do it.)这不一定是最有效的方法,但对于低吞吐量的应用程序,它应该工作得很好(我们有一个内部应用程序,每天处理大约 10 个请求,这正是我们的做法。)

If you decide to be a bit more ambitious and cache the parsed document in memory, you need to be aware that the default DOM implementation in Java is not thread-safe - even for read-only access.如果您决定更加雄心勃勃并将已解析的文档缓存在 memory 中,您需要注意 Java 中的默认 DOM 实现不是线程安全的 - 即使对于只读访问也是如此。 That's one of the reasons why I advise people to go with a third-party tree model such as JDOM2 or XOM.这就是我建议人们使用第三方树 model(例如 JDOM2 或 XOM)的 go 的原因之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM