[concurrency-interest] Locks with try/finally

Ernst, Matthias matthias.ernst at coremedia.com
Fri Jul 1 01:42:21 EDT 2005


this pattern is not specific to j.u.concurrent api but is the right way to deal with try-finally. With files, sql connections, ... I always do:

<open resource>
try {

} finally {
  <close resource>

If <open resource> returns a value, like with #getConnection,
the compiler's flow control will do the reasoning for you:

Connection connection;
try {
  connection = ds.getConnection();
} finally {

will give you an error: if #getConnection fails, connection will not have been assigned.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20050701/05cd5efc/attachment.htm

More information about the Concurrency-interest mailing list