I understand that an attempt to write to a JSON file concurrently can lead to a deadlock. Having said that I have two questions.
1 - Does reading a JSON file concurrently using Javascript cause a deadlock?
2 - If reading a JSON file concurrently using Javascript causes a deadlock how do I rectify this problem without using a database?
I am planning to host my web site on godaddy web server and I’m not using any framework such as Asp.net or Java framework. My web site consists of HTML, Javascript, JSON, and CSS files at the moment.
So the answer is you have no concurrency unless you code it yourself. Javascript doesnt open file pointers. It can get file data from a publicly available source, but that data is local to the instance once loaded.
My web page fetches data from a JSON file using AJAX when a button on my page is clicked. If I have multiple users trying to simultaneously read from the previously mentioned JSON file you are saying it will probably cause deadlocks unless I handle it through code?
If so, can you please show me or point me to a tutorial that shows how concurrency is achieved using Javascript.
It wont cause deadlocks because the webserver should handle file requests (effectively) in serial. It will receive the requests in the order the users push the button, and send the file’s contents to them. At that point, the users have ‘read’ the file, and its contents are sitting in whatever mechanism you use to store it on their browser end (Variable, data assignments, etc. Whatever’s in the “success” section of your ajax call)
At that point, each user has a memory copy of the file sitting on their own computer, that is not in any way tied to the file sitting on your server. If a user modifies their version of the ‘file’ (the variable or whatever), those changes are not stored anywhere - if the user refreshes the page, their changes are gone.
The only way a user could maintain their changes is to transmit the data back to the server with another AJAX call, presumably a POST call to a script that receives it and makes changes to the file. When a second user submits to that script, what it does is up to how you coded the receiving script.
Concurrency… I dont want to say ‘doesnt happen’, because google docs is a thing. But that level of scripting is wayyy beyond ‘point me to a tutorial’ or asking on a forum. Theoretically, you could script it so that every time someone pushes a key in the document, a request is made to the server, which receives the change, and puts that change in a queue for everyone else’s scripts to read and make to their own version of the document, and everyone’s javascript is constantly pinging the server to see if there’s been a change.
Is there a particular reason you want to do this and not use a tool like google docs that already exists with this level of complexity?