This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Hi, Working on a code where I will provide a class to read/update some attributes. Options with me are: Store in DB Store in Property File Store in an Interface. I decided to go for the Property File. I thought I will make a singleton class and will read the attributes during the loading of class. Because there will be a silgle instance every call (read or update) will go through it. Everything going fine. But hey!! In distributed env where we can have more then more then one JVM, how this is going to work. Is there any work around? Then I thought, drop the idea of singleton class, I will read the attributes from the property file and everytime somebody trys to read a attribute, I'll check the timestamp of the file. If it is different from the previous one, Update the properties. Is this the right approach? Isn't this going to be performance overhead. I know this might be a common problem. Is there any alternate or better way to go about this. Would appreciate your response.. Shikhar
File.createNewFile() is atomic, so you can use it to implement reliable inter-JVM file locking when accessing the properties file. It won't be mind-boggingly efficient but it may well be efficient enough. But really, if this file is going to be updated by multiple processes a DB-based solution would've been the best way to go. - Peter