When close HttpConnection?

Hi guys.

My application is using HttpConnection.

HttpConnection variable is set by local authorities. And the application receives the data in the thread.

You can see using my code to the following:

private class HttpConnThread implements Runnable {   Thread thread;

   public void run() {      try {     HttpConnection httpConnection = null;     httpConnection = (HttpConnection)Connector.open("http://www.domain.com");   httpConnection.setRequestMethod(HttpConnection.GET);          int resp = httpConnection.getResponseCode();          if(resp == HttpConnection.HTTP_OK) {              InputStream hInput = httpConnection.openInputStream();        InputStreamReader isr = new InputStreamReader(hInput);              //.............              //........ Do somthing              //.............              hInput.close();              isr.close();              httpConnection.close();          }      } catch(Exception e) {

      }   }

   public void start() {      thread = new Thread(this);      thread.start();   }

   public void stop() {      thread.interrupt();   }}

So, my question:

1. What is the best way to declare my HttpConnection? local or global?

2. When would end HttpConnection (httpConnection.close ())?

I think that the application should call httpConnection.close () when the application exits.

I don't know that these issue (close(), local or global), so I'm confirming their.

Thank you guys.

The best thing I would say is to close all open connections the finally block of the test socket {}... Also declare the variable HttpConnection, before the try block...

Thank you

Tags: BlackBerry Developers

Similar Questions

  • You removed the notification of 'out' when close FireFox v18 and above. Can this be restored? (our Ajax application depended on)

    Since version 18, FireFox sends more notification of 'out' when the browser is closed. Our Ajax application depends on this notification to logout of the application. Now, without such notification, the session of the app not close when the user closes their browser.

    Note that other browsers (for example. IE and Chrome) send this notification of release.

    See:

  • SkinnablePopUpContainer: What happens when close() is called

    Hello

    When I call close on a SkinnablePopUpContainer, what happens to events for her listeners the variable that contains the reference, the properties defined in it and so on?

    For example, in my app to check if there is a screen I do the following:

    Instantiate

    Popup = new mySkinnablePopUpContainer();

    popup.addEventListener (PopUpEvent.CLOSE, popupClsoe);

    ...

    private void popupClose(event:PopUpEvent):void

    {

    Popup = null;

    }

    And basically, I check if the popup is null. Is there another way to do this?

    Thank you.

    Remove you the earphones and jut certainly reduce to zero any reference you can think. The chances of the object is garbage collected.

    C

  • Get exceptions expired when using HttpConnection

    I'm reading the information from a site, for example ("http://www.mysite.com/page.html") in my application.  I'm doing a call on the site using Connector.open ("http://www.mysite.com/page.html"), but the connection just times out.

    I also tried to set deviceside = true, as written here: http://digitalsonata.blogspot.com/2009/04/blackberry-connection-tip.html, but that no longer works.

    I am currently having this run on a device with an OS to v4.5.  It works fine on the device Simulator, but it fails as described when it is deployed on a real device.

    All ideas of code examples on reading my site would be appreciated.  Thank you.

    « ; deviceside = true' by itself, without parameters APN or WAP specific carrier, is not going to work on 90% of carriers.

    See the sticky thread on this forum of Peter Strange for more information.

    Also see this article:

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

  • I can't get several tabs to stay when I close Firefox... no info on tabs don't either!

    I just got a new computer and try to install Firefox as my browser. I can't find anything about how to keep multiple tabs when close Firefox, and then come back later. They are all gone, and I have to start over. The only discovery of FAQ Ican ask how to REMOVE several tabs... I want the opposite. Help, please... I don't want to go to Internet Explorer.

    Thank you.

    Amy Klokner

    Hi Amy, one or two things immediately come to mind.

    First of all, you have Firefox start with your windows and tabs from your previous session value? This article described in dialog boxes can be set only: to restore previous session - configure when Firefox shows your most recent tabs, windows and. (Go to "Configuration session restore")

    Note: even if you start on your home page, you should be able to use the restore previous Session in the menu background.

    Second, how do you close Firefox? The best way - from the perspective of pick-up where you left off - is to use the exit on the menu (File menu in the classic menu bar, or the compact menu displayed by Firefox orange button). If you close windows individually using the Red Cross, or if you right-click on the taskbar icon and select close all windows, and then when you start, Firefox can display the last window or the last tab that was closed.

    To view your troubleshooting information, if that is not displayed in the menu help, you can type or paste Subject: support in the address bar and press ENTER.

    Firefox session restore feature is a bit fragile: sometimes updating software will launch a new Firefox window session and if you shut up without restoring your session, poof, your windows and tabs have disappeared. If you rely on session restore, consider using Session Manager extension to allow you to return to its previous sessions: https://addons.mozilla.org/en-US/firefox/addon/session-manager/

  • Previous open the tabs aren't there when I open FireFox V 24.0

    I down loaded version 24.0, and when close to Firefox all of my previous tabs have disappeared when open it again. Why? On the previous who did not.

    Control the setting in firefox... it probably varies... access settings in the tab "General".

  • TouchEvent (error) this.close

    I'm closing a screen if the user touches the screen, but a buttonfield is not selected.  I decided to try to get under the TouchEvent for screen

    protected boolean touchEvent (TouchEvent message)
    {
    If (message.getX (1) > 96 |)  message.getY (1)<>
    {
    This.Close ();
    }
    Returns true;
    }

    But I get an untrapped Exception that says ' called when close() appears not.»  This does not seem possible, I can see the screen on the Simulator and debugger says 'this' is the screen that I want to close.  I'm a bit confused.

    Any help is appreciated.

    I couldn't solve this one, even with a little help from RIM.

    I found a work-around, however.  I created a 'empty' button I called ExitMenu and I also have a Manager custom to display the button of ExitMenu off the screen.  I then gave focus to the ExitMenu button when generating a key event upward.  In this way when I clicked on the screen, but NOT on a buttonfield, ExitMenu button has the focus, and it generates an event fieldchanged I could capture and use to close the screen.

    Feel free to post a reply if you need more information or the sample code.

  • Close button of the palette UI shooting onClose callback multiple times

    Hello

    When you do:

    palette.onClose = function() { ... }
    
    
    

    ... and then clicking the close button (the small circle of OS UI in the upper left corner), in the UI of the pallet the onClose triggers recall at least 20 times.

    Why? Is this a normal behavior?

    Disabling the OS user interface when close button (using option closeButton: fake) and create a button instead:

    palette.myCloseButton.onClick = function() { ... }
    
    
    

    The onClick is triggered only once and the palette window is closed.

    Everyone notices this difference? Is it me?

    I'd love to not have a close to my palette button... I prefer to use the narrow circular button UI OS (but not if he's going to fire the recall several times in a row).

    Thank you!!!

    I did a simple test, and it does not seem to be fired only once on my computer Mac Yosemite.

    #target illustrator-19
    function test(){
      var w = new Window("palette", "Test");
    
      var lbl = w.add("statictext", undefined, "Test");
    
      w.onClose = function(){
      alert('closed.');
      };
    
      w.show();
    };
    test();
    
  • How to move a virtual machine to another host ESXi running when HA vCenter is not operational... !

    Hey

    We have a few guests of ESXi running the 5.0.0 original version and some running the latest 5.1 U1 or whatever and the last vCenter to do this too.

    the vCenter server is one of the hosts running 5.0.0 and these do not allow HA either active correctly. The problem is a known bug, and you switch to maintenance mode and do funky stuff on the cli to make it work. However, I just want to spend all my virtual machines off the old 5.0.0. hosts and on the new, as the 'old' will be dismantled. I can do all virtual machines by just when close them down and moving off, but I won't be able to do this in with the vm off vCenter vCenter!

    can I turn off, connect directly to the ESXi host, remove it its inventory (this option exists even on the ESXi host live?) and save it to the new 5.1.0 host U1 and fire?

    vCenter complain or fail when she returns to the top?

    they share all the same warehouses of data, so I need to move the backend.

    thoughts?

    Thank you

    Roger

    HA and vMotion (i.e. live migration) are two different things and are independent of each other, so if vMotion is configured correctly, you should be able to migrate the virtual machines (including the vCenter Server VM) to another host.

    André

  • LR 4.4.1 crashing on iMac osx 10.8.5 when you use the exposure and shadows. Does not restart with about reset surge protector. Worked perfectly for 1.5 years of upgrades to 4.4

    Hello

    Thanks for any help you may have. 4.4 LR worked perfectly on iMac 27' OSX 10.8.5 for 1.5 years until October this year when close downs began before making the adjustment on mainly the exposure sliders and shadow. Unit will not re-start less wait reboot power surge will become after 10-15 minutes. Apple replaced the card main and erased the disc. Backup LR 4 recharged and upgrade 4.4.1. New protection against overvoltages or directly in decision-making makes no difference and stop occurs immediately after moving the cursor. An old man can make suggestions or auto checks? This is the teacher/student version.

    Thank you dj. I'm going back to Apple and let him until he succeeds (the sixth time, as its under warranty) any other suggestions anyone?

  • Game activate when: "the page containing the content is open" for Rich Media

    Hi all

    I'm trying to set the launch for my multimedia content (mp3).

    I need to put

    Activate when the "opening of the page containing the content.

    Disable when "close the page that contains the content.

    Create poster from file

    So far, thanks to Uwe I can access the drive using

    var rm = this.getAnnotsRichMedia (0) [0]

    I also have to start and stop using rm.callAS (...)

    But I can not yet understand how to set these parameters.

    Screen Shot 2014-12-12 at 02.00.41.png

    Unfortunately, the main interface between Flash Player and Acrobat JSAPI is a long way from reliable (and when FP has been decoupled and sandbox, it got worse). I'll have to run tests, but I suspect, there is no solution by script - and don't hold your breath waiting for the API get new function calls. You are * supposed * to set the properties on each RMA through the application of creation or the RAM > properties in Acrobat Panel; the fact that a workaround is borked not inconvenient for engineering.

  • save changes to disk when you quit LR

    Hello - i have done some research in the forums and can't seem to find my exact question and answer: when close LR, I used to open a pop-up window asking me if I wanted the back upward turns into a disc. I have this window open and do not know what I did to lose it. How to restore? Thanks in advance-

    Reach:

    Edit > catalog settings > General

    Under backup, select from the drop-down list:

    Whenever the fate of Lightroom

    Note on Mac OS go to: Lightroom > catalog settings > General

  • "Détarer" problem with the Torch 9800/Device Simulator

    Hello everyone,

    Im a very strange problem with the Torch 9800 (OS 6).

    I have an application developed with 5.0 SDK. Throughout the process of synchronization of this app, there is a point he gets a. tar.gz file that is unziped. For this purporse (in fact, the tar part / "détarer"), we use a tar / "détarer" 'library' we found here in the forum (http://code.google.com/p/j2metar/). This library works fine in all phones with OS 5.0 that we try and even on the simulators of somo 6.0.

    But there seems to be a problem with the torch. During the uncompress, there are an exception, because what is the reading of the structure of the tar (from the industry), load the bytes that are invalid, corrupt, dirty, memory, and it fails.

    The strange thing of all is that if I have only the routine détarer to the file (in the torch), it works! But when I run all my sinchronization, which open and close httpconnections and process the file on some points (sometimes the same point, others of different) fails.

    My question is... are at - it a known bug, issue, etc. with the BONE of the torch (touch device)? Of course, the first thing that jump to mind is "my code is incorrect, memory leaks (in Java, but perhaps odd that a stream was not getting close properly)" and so on, but I can't seam to find the problem. And like I said before, this application works fine with the same file tar.gz in other devices like the 8520 OS 5, 9780 OS 6, 8900 (OS 5).

    IM completely stuck with this problem and any help/test will be greatly appreciated.

    Here some code, the method that makes him détarer and calls the détarer/tar library:

    public static boolean "détarer" (String tarFileUrl, String destUrl) bird Exception {}

    FileConnection fconn = null;
    FileConnection tarFileConn = null;
    TarInputStream tis = null;
    Boolean bRet = false;

    try {}
    fconn = (FileConnection) Connector.open (destUrl, Connector.READ_WRITE);
    If (! fconn.exists ())
    fconn.mkdir ();   Create the folder if it does not exist
    fconn. Close();
    fconn = null;
                
    Create a TarInputStream
    tarFileConn = (FileConnection) Connector.open (tarFileUrl);
    TIS = new TarInputStream (tarFileConn.openInputStream ());
    tarFileConn.close ();

    Entry TarEntry;
    int count;
    data Byte = null;
                
    While ((input = tis.getNextEntry ())! = null) {}
    Count = 0;
    data = new ubyte [2048];

    fconn = (FileConnection) Connector.open (destUrl + entry.getName (), Connector.READ_WRITE);
    If (! fconn.exists ())
    fconn. Create();   create the file if it doesn't exist
    else {}
    fconn. Delete();    Create a new
    fconn. Create();
    }

    OutputStream os = fconn.openDataOutputStream ();
                    
    While ((count = tis.read (data))! = - 1) {}
    OS. Write (data, 0, count);

    }
                    
    OS. Flush();
    OS. Close();
                    
    fconn. Close();
    fconn = null;
               
    }

    TIS. Close();
    TIS = null;
                
    bRet = true;
                
    } catch (Exception e) {}
    e.printStackTrace ();
    throw e;
    } {Finally
    try {}
    If (tis! = null)
    TIS. Close();
    If (tarFileConn! = null)
    tarFileConn.close ();
    If (fconn! = null)
    fconn. Close();
    } catch (Exception e) {}
    }
            
    Return bRet;
    }

    Thank you!

    Santiago.

    Hello

    It is a problem with the OS 6.  I've posted about this before here:

    http://supportforums.BlackBerry.com/T5/Java-development/reading-and-writing-file-on-torch-9800/TD-p/...

    Basically, corruption may occur if you write to the stream simultaneously in different threads.  The solution is to ensure that a single file operation is occurring at a given time.  Some people have had the chance to control the size of the buffer to something as a multiple of (64 * 1024)-1. e.g. 65535.  In addition, you can rinse after each write to the buffer.  I have had no luck with this, but others.  If you look at the bug in JIRA, there is also no activity on this:

    https://www.BlackBerry.com/jira/browse/JAVAAPI-1513

    Good luck!

  • Problem with PersistentObject.

    Hi all

    I am new to the BB and bad English (I'm Thai), sorry if you confuse in my words. I have a project that has thead to download the server image and record in PersistentObject using my CustomHashTable. The problem is that I have an error message "NonPersistableObjectException", which is based on the method "persistentObject.commit ();" in "getEncodedImage()" when I debug, here is my code.

    public class TestApp extends UiApplication{
    
        public static void main(String[] args) {      UiApplication app = new TestApp();        app.enterEventDispatcher();   }
    
      TestApp(){        pushScreen(new TestScreen()); }}
    
    public class TestScreen extends MainScreen{
    
       EncodedImage encodedImage;    CustomHashTable persistentHashtable;  private DataInputStream dis;  private byte[] encodeData;    private ByteArrayOutputStream byteStream; PersistentObject persistentObject = PersistentStore.getPersistentObject(0x61a0ab9f850b5c9bL);
    
      TestScreen(){     super();      if (persistentObject.getContents() == null) {         persistentHashtable = new CustomHashTable();          persistentObject.setContents(persistentHashtable);            persistentObject.commit();        }else {           persistentHashtable = (CustomHashTable)persistentObject.getContents();        }     encodedImage = getEncodedImage("http://download.magikmobile.mobi/scodp/mpreview.do?idc=683979&size=140x90&","4952","hot");       encodedImage = scaleImage(encodedImage);
    
          this.setTitle("Test my app");     this.add(new BitmapField(encodedImage.getBitmap()));  }
    
      public EncodedImage scaleImage(EncodedImage image) {      int displayWidth = Fixed32.toFP(Display.getWidth());      int imageWidth = Fixed32.toFP(image.getWidth());      int scalingFactor = Fixed32.div(imageWidth, displayWidth);        EncodedImage scaledImage = image.scaleImage32(scalingFactor, scalingFactor);      return scaledImage;   }
    
      public EncodedImage getEncodedImage(String url, String id, String catagory) {
    
           EncodedImage enc = null;      if (persistentHashtable.containsKey("EncodeImage01")) {           enc = (EncodedImage)persistentHashtable.get("EncodeImage01");     }
    
            if (enc != null) {          System.out.println(">>>>>  image not null");            return enc;        } else {            System.out.println(">>>>>  image null");            try {                String newURL = null;                while (url.indexOf("&") > 0) {                    newURL = url.substring(0, url.indexOf("amp;"));                    url = url.substring(url.indexOf("amp;") + 4);                    url = newURL + url;                }
    
                    newURL = null;                String suffix = "";                HttpConnection httpConnection = (HttpConnection) Connector.open(url+suffix);                httpConnection.setRequestMethod(HttpConnection.GET);                if (httpConnection.getResponseCode() == 302) {                   boolean b = true;                    while (b) {                        if (httpConnection.getResponseCode() == 200) {                            b = false;                            break;                        }                        httpConnection = (HttpConnection) Connector.open(httpConnection.getHeaderField("Location"));                    }                }                dis = httpConnection.openDataInputStream();                int length = (int) httpConnection.getLength();                if (length > 0) {                    encodeData = new byte[length];                    dis.readFully(encodeData);                } else {                    byteStream = new ByteArrayOutputStream();                    int ch;                    while ((ch = dis.read()) != -1) {                        byteStream.write(ch);                    }                    encodeData = byteStream.toByteArray();                    byteStream.close();                    byteStream = null;                }                dis.close();                dis = null;                httpConnection.close();                httpConnection = null;                try {                    enc = EncodedImage.createEncodedImage(encodeData, 0, encodeData.length);                } catch (OutOfMemoryError e) {                  System.out.println(">>>>  OutOfMemoryError");                    e.printStackTrace();                    return null;                } catch (NullPointerException e) {                 System.out.println(">>>>  NullPointerException");                    e.printStackTrace();                    return null;                } catch (IllegalArgumentException e) {                 System.out.println(">>>>>  IllegalArgumentException");                    e.printStackTrace();                    return null;                } catch (ArithmeticException e) {                  System.out.println(">>>>  ArithmeticException");                    e.printStackTrace();                    return null;                }                encodeData = null;                persistentHashtable.put("EncodeImage01", enc);                persistentObject.commit();                catagory = null;                id = null;                url = null;                return enc;            } catch (SecurityException ex) {                ex.printStackTrace();                return null;            } catch (IOException ex) {                ex.printStackTrace();                return null;            }        }    }
    
    }
    
    public class CustomHashTable extends Hashtable implements Persistable{
    
    }
    

    What should I do?

    Thank you very much

    ~ MazMellow ~.

    I see no problem here, hashtable will have any object as second parameter to the function, so you can put hashtable in storage of place (it is supported and commonly used):

    Hash hash = new Hashtable();

    data Byte [] = image.getData ();

    Hash.put ("first", data);

    ....

    ...

    ...

    ....

    data Byte [] (byte []) = hash.get ("first");

    image = EncodedImage.createEncodedImage (data,...);

  • How can ensure me that I am connected to the Wan, not the Base Station?

    I have one extreme as a base station, with an express the upstairs of the extension of the network. There are green lights on both, the utility displays the Express connected to the extreme and it is not a big house, so it seems that the network is configured correctly.

    However, when I'm near the Express, my MacBook Pro connection speed is significantly slower: 9Mbps, vs 30Mbps when close to the extreme. As far as I know, I am always connected the low extreme, rather as the Express I sit beside.

    Is there a way to say that I am connected to? Or y at - it a way to choose who to connect to?

    Thank you-

    In AirPort Utility, click images extreme and Express. A list of connected devices appears in the windows that appear.

Maybe you are looking for

  • compatibility of web cameras

    * The title must be 2 to 200 characters.

  • Look2me removal

    How can I safely get rid of my Vista Vostro 1700 Look2me infection, I see that some programs to damage the computer to remove look2me so I'm a little worried, it is located at C:\Dell\Drivers\R188840\DIAGS\sed.exe

  • -VPN - PROBLEM IOS CLIENT!

    -Start ciscomoderator note - the following message has been changed to remove potentially sensitive information. Please refrain from publishing confidential information about the site to reduce the risk to the security of your network. -end of the no

  • That means: fbkKy__0 means?

    HelloJDev 11.1.2.4I have a request (VO + VC) that throws an exception that makes sense. The SQL generated by the ADF has added a clause where clauseAND XXX. RHD_NBR =: fbkKy__0and the error message isCaused by: java.sql.SQLException: try to set a par

  • Partitions of JBoss - the FMS to create criteria

    What are the rules for Foglight determine whether an instance of JBoss is part of a JBoss cluster?  I have a few instances use multicast addresses because they are part of a JBoss cluster.  I have an instance that is a stand-alone instance of JBoss,