Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6313849
Votes 1
Synopsis Provide API to close/disconnect an UrlConnection
Category java:classes_net
Reported Against
Release Fixed
State 3-Accepted, request for enhancement
Priority: 5-Very Low
Related Bugs
Submit Date 21-AUG-2005
Description
A DESCRIPTION OF THE REQUEST :
Provide a method on the UrlConnection class to free all connected resources, e.g. close opened input and output streams.

Proposed method name: disconnect()

JUSTIFICATION :
Some methods on the UrlConnection class, such as getContentLength, might silently connect to network resources, without releasing them again. I assume that releasing them again and again might be too costly. Still, a way to easily free all those resources explicitely when done would be handy.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All external resources occupied while working on the connection are freed.
ACTUAL -
No such method seems to be available.

---------- BEGIN SOURCE ----------
/* Example showing resource allocation for a file url connection */

import java.io.File;
import java.net.URLConnection;

public class FileUrlGetContentLength {
  public static void main(String[] args) throws Exception {
    File file = new File("foo.txt");
    file.delete();
    System.out.println("create: " + file.createNewFile());

    URLConnection connection = file.toURL().openConnection();
    connection.getContentLength();
    //    connection.getInputStream().close();
    System.out.println(file.delete());  // *** deleting the file will fail unless above line is uncommented
  }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Knowing which methods access which resources (such as the input stream) close those resources explicitely.

Although the JavaDoc states that this might be necessary, it isn't a very obvious or elegant way of doing it.
Posted Date : 2005-08-21 09:00:38.0
Work Around
N/A
Evaluation
N/A
Comments
  
  Include a link with my name & email   

Submitted On 14-JUL-2008
I think there should be a method to monitor the status of  the UrlConnection (just like HttpRequest does)



PLEASE NOTE: JDK6 is formerly known as Project Mustang