The try-with-resources Statement
There is a big full stop for the resource leak in JAVA.Instead of breaking our heads to properly releasing used resources after its usage,
from JAVA SE 7 onwards we just need to focus only on business using those resources.
Past couple of decades, we followed as best practice in releasing the resource using the finally block.
FileReader fr = new FileReader("text.txt");
BufferedReader br = new BufferedReader(new FileReader("text.txt));
try {
System.out.println( br.readLine());
} finally {
if (br != null) br.close();
if (fr != null) fr.close();
}
Many of the close() function implementation will close themself, and makes a no mark in system.
However, few times it may do additional task to release its parent also. For instance, ResultSet.close() implementations.
From JDK 7 onwards, any resource object which extends either java.lang.AutoCloseable or java.lang.Closeable can be instanciated in try statement. Those resources automatically get closed after try block executions.
For the resource implementor, its recommended not to throw any exception while doing close() call.
And align the resource close operation such that it is closing itself.
try (FileReader fr = new FileReader("text.txt");
BufferedReader br = new BufferedReader(fr)) {
System.out.println( br.readLine());
}
7 comments:
https://istanbulolala.biz/
MAA3L
yalova evden eve nakliyat
tunceli evden eve nakliyat
giresun evden eve nakliyat
ağrı evden eve nakliyat
van evden eve nakliyat
YZZ4D
urfa evden eve nakliyat
malatya evden eve nakliyat
burdur evden eve nakliyat
kırıkkale evden eve nakliyat
kars evden eve nakliyat
NCF
19FD0
Star Atlas Coin Hangi Borsada
Mardin Evden Eve Nakliyat
Eryaman Boya Ustası
Area Coin Hangi Borsada
Çerkezköy Sineklik
Ünye Organizasyon
Düzce Şehir İçi Nakliyat
Siirt Evden Eve Nakliyat
Bitrue Güvenilir mi
تسليك مجاري بالهفوف CcHL2Wrztw
شركة عزل مواسير المياه بالجبيل McHlkmUeLD
شركة عزل اسطح بام الساهك NtFAEqACrh
Post a Comment