开发者

Dealing with concurrent access to an XML file using a java server

In the application Im writting the server will have information abuot the users, using a XML databse. The admin user will be able to write/read information on those files too. How can I deal with concurrent access to those files? The only way users/admin can read/write to those files is by requesting to the server(Sockets, TCP connection), so the server will have to handle this. What can I do? I could s开发者_JAVA百科ynchronize server methods, but I dont want to avoid USER A to access his files while the admin is writing on USER B files.


Use a database instead of files is my first suggestion, they handle locks already.

You should post an example of file structure. It could be done if User A has his data in fileA.xml and user b has his in fileB.xml by locking the given file and synchronizing based on that.


As Jes says use a database.
MySQL Supports XML: http://dev.mysql.com/tech-resources/articles/xml-in-mysql5.1-6.0.html
Most databases support XML, or you could simply use a VARCHAR that is long enough and get and put the data in there. If that is your plan then maybe a NoSQL Solution would work also, it is just a persistent HashMap that supports record locking as well as other features.

It sounds like there is no conflict between users, what you could also do is have an area for the admins to modify the files, which you would copy daily to where the data is read from for the users.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜