java - Is File instance thread safe? -
I've read that Examples of this class may or may not be an actual file-system object such as a file or directory. If such an object specifies, that object remains in a partition. A partition is a operating system-specific part of storage for a file system, a single storage device (eg a physical disk-drive, flash memory, CD-ROM) can have multiple partitions < P> So I'm curious if such a code is safe in a multithrred environment: For example, Thread 1 comes here, creates an example and is starting to work Meanwhile, In thread 2, it is interrupted, the example makes by the same name (myfile.zip) and performs some other operations. After that he saved the file. I need to make sure that they do not work with the same file and the previous thread overwrites the previous one to save the file. No, the file does not keep locked and is not safe for the pattern you describe. File should be locked or placed in the wrapper class. If you provide a bit more code, then one can definitely help you find a suitable pattern. new file ("path") does not physically make a file on disk is . Although it is said in the API:
file file = new file ("myfile.zip"); // Take some action with file (fill it with content) file.save (anywhere); // Simply show that I save it after a number of tasks
Comments
Post a Comment