|
SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here. |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
Question about using the properties class in java
So I have a question and was curious what other people thoughts are on the issue. I am using the java properties class to read and write to a properties file (seperate from sage's for my own reasons). What is the best practice on loading the inputstream(properties file) and closing it. My initial thought is to load it and keep it loaded in memory until it is written to or changed at that point dump it and reload it.
Is this an acceptable method or am I much better of opening and closing the stream every time I read/write to it? cheers and TIA pluckyhd |
#2
|
||||
|
||||
Quote:
so it might be something like... Code:
Properties props = PropertiesManager.loadProperties(); props.setProperty("x","10"); props.setProperty("y","20"); props.setProperty("z","30"); PropertiesManager.saveProperties(props); I'd avoid doing loads/saves with each set, since it can generate a lot of overhead. Another approach might be to load the properties on startup, and then use the addShutdownHook() to add a shutdown hook that saves the properties when the jvm is shutting down. The downside to this, is that if the jvm crashes, then the shutdown hook is never called and the changes are never written. Another approach might be to use a TimerTask inside the PropertiesManager instance to save the properties at some predefined interval. But, by far the most reliable means is to handle the loading and saving of the properties when you need it to happen. ie, the first approach good luck.
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#3
|
||||
|
||||
What I would do is open the file, initialize the properties object, and then close the file. I'd do this just once either at startup or on the first use of the properties object.
I'd then keep the properties object around for the duration of the session. Saving properties back to the file would depend on how often they change. If properties change only in response to user commands, then I don't see a problem with saving to disk every time a property changes. It's simple and fairly low overhead. If properties change faster than user speed, for instance if you're using properties as temporaries in some looping computation, then I'd say to rethink your use of properties for that purpose. Use in-memory variables instead, and save them as properties only after the entire computation is finished and control returns to the user. Saving should follow the same model as loading: open the file, save the properties, then close the file. I don't see any reason to hold the file open for the duration of the session unless you specifically want to lock out other programs (e.g. text editors) from accessing that file in the meantime.
__________________
-- Greg |
#4
|
|||
|
|||
Thanks you guys I am not sure which way I will go yet, but glad I was on the right path at least I will probably initialize the property object and then close the stream.
The changes will be caused by user interaction so I can easily add hooks to when they close the options menu it writes it back to the property and reinitialize the property object again. |
#5
|
||||
|
||||
Why do you want to reinitialize the property object? Initializing it once ought to be enough. Saving it back to disk when properties change is then sufficient to bring the file copy back into sync with the in-memory copy. Reloading from disk after a change shouldn't be necessary.
__________________
-- Greg |
#6
|
|||
|
|||
Quote:
|
#7
|
|||
|
|||
Got another one Why when storing the properties file using propfile.store() does it not automatically sort like sages properties files do. Is there a code I am missing somewhere to store it sorted?
|
#8
|
||||
|
||||
The properties class is not designed well in the sense that it extends Hashtable but that's a whole other discussion. What it means for you is that it's not sorted. Here's one way to do it.
__________________
Server: Intel Core i5 760 Quad, Gigabyte GA-H57M-USB3, 4GB RAM, Gigabyte GeForce 210, 120GB SSD (OS), 1TB SATA, HD HomeRun. Extender: STP-HD300, Harmony 550 Remote, Netgear MCA1001 Ethernet over Coax. SageTV: SageTV Server 7.1.8 on Ubuntu Linux 11.04, SageTV Placeshifter for Mac 6.6.2, SageTV Client 7.0.15 for Windows, Linux Placeshifter 7.1.8 on Server and Client, Java 1.6. Plugins: Jetty, Nielm's Web Server, Mobile Web Interface. |
#9
|
|||
|
|||
That did it thanks a bunch.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Question about Sage.properties | pjpjpjpj | SageTV Software | 2 | 10-17-2008 06:04 AM |
SageClient.properties Question - videoframe/ | osburnfamily | SageTV Software | 3 | 07-25-2008 01:25 PM |
sage.properties question about available_channels | pez | SageTV Software | 4 | 01-10-2008 07:25 AM |
properties file question | dvd_maniac | SageTV Software | 2 | 12-10-2004 11:34 PM |
SageRecorder.properties question | kenb | SageTV Recorder Software | 0 | 10-28-2004 07:17 PM |