Managing Resources with Java 7

A very clear and detailed article by Julien Ponge, titled “Better Resource Management with Java SE 7: Beyond Syntactic Sugar,” presents the Java 7 answer to the automatic resource management problem in the form of a new language construct, proposed as part of Project Coin, called the try-with-resources statement.

Java applications frequently manipulate different types of resources such as files, streams, sockets, and database connections that require system resources for their operations. They must be managed with great care or risk having database connections and file descriptors remain open after an exception occurs elsewhere in the code. As a result, application servers may need frequent restarts due to resource exhaustion.

The article provides an overview of resource and exception management before explaining the essentials of try-with-resources statements. It then shows how a class can be made ready to support such statements, and concludes with a demystification of the syntactic sugar behind the language extension.

Ponge concludes that the try-with-resources construct “generates correct code on behalf of the developer, eliminating the need to write boilerplate code that is easy to get wrong. More importantly, this change has been accompanied with evolutions to attach one exception to another, thus providing an elegant solution to the well-known problem of exceptions masking each other.”

Read the rest of the article here.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Insider News from the Java Team at Oracle!

duke
javeone logo
Links


Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
2
5
6
7
12
13
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today