PropertiesConfiguration.java
hat keine close()
Methode. Gibt es noch etwas, das getan werden muss, um die Datei freizugeben? Ich möchte sicher sein, bevor ich das in der Produktion verwende. Ich habe den Code durchgesehen und sehe nichts. Ich bin mir nicht ganz sicher, wie PropertiesConfiguration.setProperty()
funktioniert, ohne eine Verbindung zu der Datei zu öffnen, die dann geschlossen werden müsste.Apache Commons Konfiguration - EigenschaftenKonfiguration geschlossen
Antwort
In org.apache.commons.configuration.PropertiesConfiguration
ist die Eingabe (Strom, Pfad, URL, etc ...) natürlich geschlossen, wenn die Eigenschaften in der PropertiesConfiguration
Instanz geladen wurden.
Sie könnten die Bestätigung in der void load(URL url)
Methode von org.apache.commons.configuration.AbstractFileConfiguration
haben.
Hier ist, wie diese Methode aufgerufen wird:
1) PropertiesConfiguration
Konstruktor aufgerufen wird:
public PropertiesConfiguration(File file) throws ConfigurationException
2), die ihre Super Konstruktor aufruft:
public AbstractFileConfiguration(File file) throws ConfigurationException
{
this();
// set the file and update the url, the base path and the file name
setFile(file);
// load the file
if (file.exists())
{
load(); // method which interest you
}
}
3), die load()
ruft :
public void load() throws ConfigurationException
{
if (sourceURL != null)
{
load(sourceURL);
}
else
{
load(getFileName());
}
}
4), die load(String fileName)
ruft:
public void load(String fileName) throws ConfigurationException
{
try
{
URL url = ConfigurationUtils.locate(this.fileSystem, basePath, fileName);
if (url == null)
{
throw new ConfigurationException("Cannot locate configuration source " + fileName);
}
load(url);
}
catch (ConfigurationException e)
{
throw e;
}
catch (Exception e)
{
throw new ConfigurationException("Unable to load the configuration file " + fileName, e);
}
}
5), die load(URL url)
public void load(URL url) throws ConfigurationException
{
if (sourceURL == null)
{
if (StringUtils.isEmpty(getBasePath()))
{
// ensure that we have a valid base path
setBasePath(url.toString());
}
sourceURL = url;
}
InputStream in = null;
try
{
in = fileSystem.getInputStream(url);
load(in);
}
catch (ConfigurationException e)
{
throw e;
}
catch (Exception e)
{
throw new ConfigurationException("Unable to load the configuration from the URL " + url, e);
}
finally
{
// close the input stream
try
{
if (in != null)
{
in.close();
}
}
catch (IOException e)
{
getLogger().warn("Could not close input stream", e);
}
}
}
Und in der finally
Anweisung ruft, können Sie sehen, dass der Eingabestrom in jedem Fall geschlossen ist.
Danke @davidxxx. Ich glaube, ich habe nicht darauf vertraut, was ich sah. – pyetti
- 1. Alle Apache Commons-Konfiguration Ersatz/Konkurrenten?
- 2. Hbase Ausnahme org/apache/commons/Konfiguration/Konfiguration nicht gefunden
- 3. commons-Konfiguration benutzerdefinierte Konfigurationsdatei
- 4. Apache Commons Konfigurationsdatei Import-Dateien
- 5. Apache Commons FTPClient.listFiles
- 6. Apache commons csv
- 7. Apache Commons JCI ReloadingClassLoader
- 8. Apache commons lang StrTokenizer
- 9. Apache commons ftp
- 10. Apache Commons Abbildungsschreibbildfehler
- 11. jar Konflikte Version commons-Konfiguration
- 12. Apache Commons IO Tailer Beispiel
- 13. Apache Commons CSV String intern
- 14. Apache commons CLI - wiederholte Optionen
- 15. Apache Commons IO in .Net
- 16. Unterstützt Apache Commons HttpClient GZIP?
- 17. Apache Commons Datei-Upload-Alternativen
- 18. Apache Commons IO Tailer verstehen
- 19. DefaultParser in Apache Commons CLI
- 20. Standardabweichung mit Apache Commons Math
- 21. Apache Commons Crypto - Getting IllegalBlockSizeException
- 22. log4j Warnung Problem - Apache Commons
- 23. Beschleunigung Apache Commons FTPClient Übertragung
- 24. Apache commons PredictedList ohne IllegalArgumentException
- 25. Apache Commons VFS Thread Sicherheit und Ressourcenmanagement
- 26. Probleme mit Apache Commons FTP-Client-Timeout
- 27. Datei mit Java Apache Commons herunterladen?
- 28. Apache Commons Net FtpClient abbrechen Dateispeicher
- 29. Interpolieren Funktion mit Apache Commons Math
- 30. Holen CSV-Datei-Header mit Apache Commons
Wovon redest du? – shmosel
In der JRE gibt es keine Klasse 'PropertiesConfiguration'. Wenn Sie es von woanders bekommen, müssen Sie es erklären. – chrylis
Ich würde annehmen, dass er über die 'PropertiesConfiguration' Klasse von Apache Commons Configuration spricht. Diese Frage kann nicht definitiv beantwortet werden, ohne zu wissen, wie Sie die 'load'-Methode verwendet haben. Als allgemeine Faustregel gilt jedoch: Wenn Sie eine Ressource öffnen, müssen Sie _you_ schließen. Wenn eine Bibliothek von buchstäblich Tausenden geöffnet wird, können Sie sicher sein, dass es richtig aufgeräumt wird. – rmlan