If I put a .jar file n a shared driver and it is been used by 2 different users with different login access. Can I synchronize their activities ? As if both the users want to upload a file at the same time, can I restrict another user from uploading the file or put that user on wait till 1st user completed its task because when a user upload a particular file the system creates a unique id for that file but when both the users upload file at the same time, the file gets uploaded with same unique code for both file.
Asked
Active
Viewed 110 times
-1
-
What does uploading files have to do with your jar file? – JSamir Feb 16 '18 at 06:30
-
2each user will have a different JVM. If you want to *synchronize their activities* consider a web server – Scary Wombat Feb 16 '18 at 06:32
-
Its a one of the task implemented in jar, which is getting impacted if both the users upload the file using same jar at the same time. – Swini Feb 16 '18 at 06:35
-
If the users are running on different computers, what would be the point? You could place "upload" requests into a common directory which could be processed by another process... – MadProgrammer Feb 16 '18 at 06:40
-
@Swini so the users log in to a computer and execute the jar file. The jar file implements a file upload functionality. If a user starts uploading you want to prevent another one from starting upload (of the same?) file. You could create a .lock file when starting an upload which signals other executed jars that they can't upload currently and then poll that file location to see when the first user is finished uploading. – JSamir Feb 16 '18 at 06:46
1 Answers
0
Whether you can or not depend on the synchronization primitives provided by the shared file system. Two different users running the jar file at the same time will use different JVM and eventually different computers. So the only possible synchronization will be a lock on a file on the shared folder.
If what you really want is to prevent different users to create the same file (and if this is not already handled by the underlying file system, some can...), you could use something like that:
- lock a file dedicated to that operation
- test if the file name you want already exists and if it does, either loop with another name or release the lock and abort
- create the file
- release the global lock
- proceed with writing the file

Serge Ballesta
- 143,923
- 11
- 122
- 252