Segfault in OCIHandleFree for a statement after closing the connection

my app has lots of statements allocated at any one time.
if the oracle connection is lost (due to temporary network problems, etc), my app detects the connection loss. when the connection is lost, the app destroys the old connection, and then tries to create a new connection. once it gets a new connection, the app goes through and destroys its old statements.
but, sometimes a segfault occurs in the call to OCIHandleFree.
when the old connection is destroyed, does it also free up all memory allocated for the statement too? so I'm basically doing a double free when I try to call OCIHandleFree on the statements?
btw, by 'destroy old connection': the app is using the oralib wrapper around the oci library. when an oralib instance is destroyed, it first switches the server handle to OCI_ATTR_NONBLOCKING_MODE, then calls OCISessionEnd, OCIServerDetach, then OCIHandleFree for each of the svc_context, session, error, and server handles.
after that, a new oralib instance is created, which makes a new connection to oracle.
then after that, the old statements will all be passed to OCIHandleFree.
is there any obvious problem with that? thanks!

It is very important to close them as you might have a resource leak. Many people think that since Java is garbage collected, they don't have to worry about memory. While this is true, it should not be take to the extreme.
public void method throws SQLException
     Connection conn = DriverManager.getConnection();
     Statement stmnt  = conn.createStatement();
     ResultSet results = stmnt.executeQuery("SELECT * FROM table;");
     results.close();
     stmnt.close();
     conn.close();
}The above code looks correct, but in fact it is not completely correct. It is not completely correct, because the release of resources is not ensured. If an exception occurs midway, it's possible that the resources will not be properly released.
Here is the correct code.
public void method throws SQLException
     Connection conn = null;
     Statement stmnt = null;
     ResultSet results = null;
     try
          conn = DriverManager.getConnection();
          stmnt = conn.createStatement();
          results = stmnt.executeQuery("SELECT * FROM table;");
     finally
          if ( results ! = null )
               results.close();
          if ( stmnt != null )
               stmnt.close();
          if ( conn != null )
               conn.close();
}The finally block ensures that even if an exception occurs we will release our resources. You have to make sure they're not null to avoid NullPointerExceptions.

Similar Messages

  • Difference between closing the connection before and after committing user transaction?

              I was wondering what's the difference between closing the connection before committing
              the transaction versus closing the connection after committing the transaction?...
              for e.g....
              Scenario 1.........
              UserTransaction useretran;
              usertran.begin();
              Connection con = datasource.getCOnnection();
              // do bunch of stuff...
              conn.close();
              usertran.commit()
              Scenario 2...
              UserTransaction useretran;
              usertran.begin();
              Connection con = datasource.getCOnnection();
              // do bunch of stuff...
              usertran.commit()
              conn.close();
              thanks....
              Srini
              

    Hi. As long as you're sure there's a transaction going on, and the connection
    is a transaction-aware object (from a TxDataSource), either will be fine.
    In the first scenario the actual semantics of the close() call are less than
    normal, because we really don't close the connection or return it to the
    pool until the actual transaction commits, and in the second case, we have
    already taken the connection out of your service as of the commit().
    The second scenario is the usual coding style. If there's ever a chance your
    code will get non-transaction-aware connections, it is crucial to close
    connections, and I always recommend putting the close() in a finally block
    so it's guaranteed to happen.
    Joe
    srinivas wrote:
    I was wondering what's the difference between closing the connection before committing
    the transaction versus closing the connection after committing the transaction?...
    for e.g....
    Scenario 1......... UserTransaction useretran; usertran.begin(); Connection con =
    datasource.getCOnnection(); // do bunch of stuff... conn.close(); usertran.commit()
    Scenario 2... UserTransaction useretran; usertran.begin(); Connection con = datasource.getCOnnection();
    // do bunch of stuff... usertran.commit() conn.close();
    thanks....
    Srini

  • 'You can post in new year only after closing the previous year

    Hello Experts,
    I am also getting same error while executing depreciation run AFAB ''You can post in new year only after closing the previous year''.
    I found one OSS Note 18800 and it is saying solution as below ...
    At the first depreciation posting in the new fiscal year after a shortened fiscal year, the fiscal year variants must, in all cases, still be entered in asset customizing and in FI customizing for the affected company code. If necessary, all periods for the following fiscal year must be maintained with the variant of the shortened fiscal year.
    Up to 2.2D the following correction must also be installed:
    Please carry out the syntax check only in main program SAPLAFAR.
    But in my case there is no shortended fiscal year.
    Can I apply this OSS note correction instructions ?
    Please suggest me.

    Hi
    I don't think so. Moreover that is applicable till 2.2D.
    Moreover depreciation is to be run for all periods you have not run earlier. Please check upto which period dep run has happened. Thereafter close the fiscal years in order thro AJAB.
    S Jayaram

  • MissingResourceException when I iterator a collection after closing the PM

    I retrieve a collection, call pm.retrieveAll on it, and then close the PM.
    When I try to iterator over the collection, I get a
    MissingResourceException. I can't figure out why I'm getting the exception,
    if I do a retrieveAll it should retrieve all the fields of all the objects
    in the collection. It's as if there is a rule "Thou shall not iterator over
    a collection after closing the PM". Is this true?
    java.util.MissingResourceException: Can't find resource for bundle
    java.util.PropertyResourceBundle, key resultlist-closed
    at java.util.ResourceBundle.getObject(ResourceBundle.java:314)
    at java.util.ResourceBundle.getString(ResourceBundle.java:274)
    at serp.util.Localizer.get(Localizer.java:270)
    at serp.util.Localizer.get(Localizer.java:121)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.checkClosed(LazyResult
    List.java:349)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.listIterator(LazyResul
    tList.java:403)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.iterator(LazyResultLis
    t.java:397)
    at
    com.verideon.siteguard.services.SchedulerService.getMonitorsToRun(SchedulerS
    ervice.java:103)
    at
    com.verideon.siteguard.services.SchedulerService.schedule(SchedulerService.j
    ava:59)
    at
    com.verideon.siteguard.web.util.TimerServlet$scheduleTask.run(TimerServlet.j
    ava:84)
    at java.util.TimerThread.mainLoop(Timer.java:432)
    at java.util.TimerThread.run(Timer.java:382)
    Here is my code:
    private Collection getMonitorsToRun() {
    Collection c = new LinkedList();
    PersistenceManager pm = null;
    try {
    pm = JDOFactory.getPersistenceManager();
    Extent extent = pm.getExtent(Monitor.class, true);
    String filter = "nextDate <= now";
    Query q = pm.newQuery(extent, filter);
    q.declareParameters("java.util.Date now");
    q.setOrdering("nextDate ascending");
    Hashtable p = new Hashtable();
    p.put("now", new Date());
    c = (Collection) q.executeWithMap(p);
    pm.retrieveAll(c);
    } catch (JDOException e) {
    log.warn("Received JDO Exception while retrieving Monitors " + e);
    } finally {
    pm.close();
    log.debug("Retrieved " + c.size() + " Monitors ready to be ran.");
    Iterator i = c.iterator();
    while (i.hasNext()) {
    Monitor m = (Monitor) i.next();
    log.debug("m id = " + m.getId());
    return c;

    It appears to be a query in which case, yes, a Query result Collection cannot be iterated over.
    The simple way to bypass this is to transfer the results to a non-closing Collection.
    Collection results = (Collection) q.execute ();
    results = new LinkedList (results);
    pm.retrieveAll (results);
    pm.close ();
    On Thu, 27 Feb 2003 14:49:17 +0100, Michael Mattox wrote:
    I retrieve a collection, call pm.retrieveAll on it, and then close the PM.
    When I try to iterator over the collection, I get a
    MissingResourceException. I can't figure out why I'm getting the exception,
    if I do a retrieveAll it should retrieve all the fields of all the objects
    in the collection. It's as if there is a rule "Thou shall not iterator over
    a collection after closing the PM". Is this true?
    java.util.MissingResourceException: Can't find resource for bundle
    java.util.PropertyResourceBundle, key resultlist-closed
    at java.util.ResourceBundle.getObject(ResourceBundle.java:314)
    at java.util.ResourceBundle.getString(ResourceBundle.java:274)
    at serp.util.Localizer.get(Localizer.java:270)
    at serp.util.Localizer.get(Localizer.java:121)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.checkClosed(LazyResult
    List.java:349)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.listIterator(LazyResul
    tList.java:403)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.iterator(LazyResultLis
    t.java:397)
    at
    com.verideon.siteguard.services.SchedulerService.getMonitorsToRun(SchedulerS
    ervice.java:103)
    at
    com.verideon.siteguard.services.SchedulerService.schedule(SchedulerService.j
    ava:59)
    at
    com.verideon.siteguard.web.util.TimerServlet$scheduleTask.run(TimerServlet.j
    ava:84)
    at java.util.TimerThread.mainLoop(Timer.java:432)
    at java.util.TimerThread.run(Timer.java:382)
    Here is my code:
    private Collection getMonitorsToRun() {
    Collection c = new LinkedList();
    PersistenceManager pm = null;
    try {
    pm = JDOFactory.getPersistenceManager();
    Extent extent = pm.getExtent(Monitor.class, true);
    String filter = "nextDate <= now";
    Query q = pm.newQuery(extent, filter);
    q.declareParameters("java.util.Date now");
    q.setOrdering("nextDate ascending");
    Hashtable p = new Hashtable();
    p.put("now", new Date());
    c = (Collection) q.executeWithMap(p);
    pm.retrieveAll(c);
    } catch (JDOException e) {
    log.warn("Received JDO Exception while retrieving Monitors " + e);
    } finally {
    pm.close();
    log.debug("Retrieved " + c.size() + " Monitors ready to be ran.");
    Iterator i = c.iterator();
    while (i.hasNext()) {
    Monitor m = (Monitor) i.next();
    log.debug("m id = " + m.getId());
    return c;
    Stephen Kim
    [email protected]
    SolarMetric, Inc.
    http://www.solarmetric.com

  • ITunes 10.5.3 restarts itself after closing the program. How do I fix this?

    iTunes 10.5.3 restarts itself after closing the program. How do I fix this?
    Windows 7 64bit Ultimate
    iTunes 10.5.3 64bit

    I've had this problem on my Windows XP for years. it's been around, unsolved, or no solutions in these forums.
    It keeps reminding me why Apple will never be the primary office computer company. Anyone running a business cannot have software running that will not behave, won't shut down, or behaves without any explanation, and this problem has no explanation, or solution that I can find except to use task manager to kill the process and only use iTunes when I'm expecting to shut down or kill the process.

  • SAPgui.exe is running even after closing the GUI components

    Hello All,
    Even after closing the SAP GUI components like Bex, WAD or RSA1 etc... i am able to see these processes are running under the Task Manager--> Processes....
    even if i try to restart the system, error messages are occuring...saying that SAP is still opend...
    Why it is happening, any ideas?
    Thanks,
    Ravi

    Hi Dirk,
    Thanks for your infomation. Infact, apart from this problem, i have the problem with saving the webtemplate. As it is taking much time to save a template after modifications, i had to terminate the wad process. It seems above 2 problems are related....any ideas?
    Thanks
    ravi
    Message was edited by: Ravi Pasumarty

  • Depreciation run problem."You can only post in new year after closing the"

    Hi,
    We are implementing Asset accounting to one of our co code.New Assets were created in Jan and when I tried to Post depreciation for Jan, I get an error log that says "You can only post in new year after closing the previous year."
    When i double click on error message.
    Diagnosis
    You want to post in a new fiscal year. However, a posting must have been made in the last period in the previous fiscal year before you can do this.
    Procedure
    Post to the last period in the previous year first.
    So I went ahead and opened the previous year, posted the depreciation, closed the year and tried to post Period 1 again, but still get the same error.
    Why do I need to post the previous period if I just created the assets in this period?
    I Have completed AJRW, AJAB also.
    I think it may be a problem with Table. Please suggest me.
    Thank you

    Hi,
    Please check the following :-
    1. Check the Last Closed year in your Asset Accounting.
    2. Check the Last Depreciation Posted in Your Asset Accounting.
    These 2 menus are available in "Data Transfer in Fixed Asset Accounting".
    revert back to me for further actions,
    regards
    N.Kumar

  • Premiere Pro CS 6.exe stays active after closing the program

    I am experiencing a problem with Premiere Pro CS 6.03. When I close the program, the second monitor would not return to desktop (it stays a black screen). The premiere pro cs.exe is active in taskmanager. Only after I end the exe process would the second monitor return to desktop. I am not using any third party hardware, only Adobe player for second monitor out. This problem occurs often, but not every time I use Premiere. I have never experienced this problem in Premiere Pro CS 5.03, which is still installed on the same PC. The technical Spec is: Intel 3930K, 32 GB RAM, GTX 560, Windows 7 Professional 64 bit. I have tried to toggle between different NVidia drivers, but with no effect.
    Any help would be appreciated!

    I've had the process stay open after closing the program as well, but only on one of my two machines.  For me, the 6.0.3 update seemed to correct the issue.  Not sure why it's still happening in your case.

  • Asset You can only post in new  year after closing the previous year

    Hi Experts,
    I am getting below error while running the depriciation:
    You can only post in new  year after closing the previous year.
    Message no. AA687
    Diagnosis
    You want to post in a new fiscal year. However, a posting must have been made in the last period in the previous fiscal year before you can do this.
    Procedure
    Post to the last period in the previous year first.
    Note : I closed FY09, even though there were no assets in it at the time.  The first  asset was capitalized on 12/29/09 (clearly in FY10).  I tried closing FY09 again and got the messege  No year-end close is necessary for company code XXXX .
    Could you please any one help me on this.
    Thanks In Adwance
    Regards,
    Saritha.

    Hi Saritha,
    Please check the following settings:                                                                               
    o Is there one ore more years since the last depr. run?                                                                               
    Solution: in this case an entry must be made into the table TABA. 
                      Note 144441  gives a solution to make a "Dummy-entry".                                                                               
    o If there was never a depreciation run, the there must be 000/0000 in
      TABA and T093D.                                                                               
    Solution: please take the report from the note  Note 144441           
                      and put the values  000/0000 in this fields.                                                                               
    o Do you  have a non-calendar fiscal year (e.g. 2009/10)? In this case
        you should have in the field T093D-AFBLG the year 2010.             
        Solution: Correction with note 26073                              
    regards Bernhard

  • How to Direct control to application's window after closing the popup?

    Hi,
    I am using 10.1.3. In my application I am unable to direct control to application's window after closing the popup, if I open any other window at the same time.
    For more info see the below step:-
    -> Open any popup in my application.
    -> Open any new window (lets say Google.com).
    -> Now restore popup on Google window.
    -> Now close popup
              - control goes to Google window but not the parent application window.
    How to direct control to the parent window?
    Can anybody help me regarding this?
    Thanx...Abhijit

    Hi Abhijit,
    You can do this using Javascript alone. Below are the two sample files I created.
    main.html_
    <html>
    <head>
      <title>Testing popup</title>
      <script type="text/javascript">
      function openPopup() {
        window.open("popup.html");
      </script>
    </head>
    <body>
      <a hr_ef="javascript:openPopup()">Open popup</a>
      <input id="something" name="something" type="text" value="something">
    </body>
    </html>
    Note: hr_ef should be href. The code tags are messing with the link.
    popup.html_
    <html>
    <head>
      <title>This is the popup window</title>
      <script type="text/javascript">
      function goToMain() {
        window.opener.something.focus();
      </script>
    </head>
    <body onunload="goToMain()">
      This is the popup window. Close this window to return to main window.
    </body>
    </html>The idea is to call a javascript function in the popup window that tries to focus on an object (eg. InputText) in the main html.
    Although, one point to take note is the naming of html objects by by these ADF UI Components. If you named your form id as "*form1*" and input text id as "*something*", your input text id will end up as "*form1:something*".
    Therefore, you will have to tweak the code above to the following:
    <script type="text/javascript">
    function goToMain() {
      window.opener.form1['form1:something'].focus();
    </script>Regards,
    Chan Kelwin

  • Refresh the table after closing the Popup iView

    Hi all,
    I have list of survey in my table. In that table i have toolbar button(DELETE) for deleting the survey. While deleting the survey it asks the confirmation. If we click Ok it delete the selected survey and close the popup also. what I want is I should refresh the table after closing the Popup.How can i achieve this?
    Help me in this regard.
    Thanks & Regards,
    Hemalatha J

    Hi Hema,
    Check this link.
    Visual Composer - You can do anything....
    In this blog, they are used 'Refresh' Button and a Hidden 'Plain text' message to solve this problem. If you are satisfy with this you can take this solution.
    Or you can try to trigger the 'Submit' action of 'Input form' once again from the 'Popup window' when the 'Delete' button is clicked.
    Hope it helps...
    Regards
    Basheer
    Edited by: Basheer on Dec 23, 2008 8:03 PM

  • Backend BSP session not closing on server after closing the window

    Hi All,
    We have SAP EP (7.0 SP21) and there is a BSP transaction ivew (Interaction Center ) intergrated in the portal. The issue is when the user performs any transactions inside the BSP and then closes the browser, session remains on the server till the timeout. Is there a way to end those sessions on server after closing the browser immediately?
    Portal domain : xx.mycomp.com
    ABAP system domain :mycom.com
    Should the domains be same for the DSM of Portal to work or is there any solution that can be considered.
    regards
    Uday

    Hi Uday,
    These are the main issues that can cause issues with DSM:
    JavaScript Origin Policy:
    Scripting
    between different domains is not allowed because of “JavaScript origin policy”.
    Also
    communication between mixed protocols (http\https) is forbidden.
    Therefore
    the portal server and the content server must be on the same domain and must
    use the same protocol.
    For
    detailed explanation see:
    http://mozilla.org/projects/security/components/same-origin.html
    Popup Blocker:
    •Popup blockers may cause troubles
    in relation with SRA feature.
    •Terminator handles notifications in
    new window when current window is being destroyed (logoff, closing browser
    window) – popup blocker prevents the opening of new window, hence no session
    handling performed.
    please also check SAP Note #596698 for more information typical problems and troubleshooting.
    In general, the 2 domains should be the same.
    xxx.mycomp.com, meaning that first part of the url can change but what comes after should be the same domain.
    Best regards,
    Etay

  • My iPad3 loses the 3g connection after closing the magnetic cover.

    My iPad 3 loses the 3g connection after closing the magnetic cover.  When the cover is opened, the iPad shows the connection is active.  However, it does not connect but searches for emails etc.  I have to then reboot.

    have you tried disabling then reabling the 3G setting on your iPad after waking the iPad?
    It may be that as it goes to sleep the iPad loses the 3G connection, you may be in a low connection area, and then has problems finding it again, this can happen occassional with WiFi.
    If you go into Settings, then Mobile Data and toggle  the On/Off switch Off, then On again, see if that brings it back without restarting the iPad.

  • You can only post in new year after closing the previous year.

    Hi,
    I got error "You can only post in new year after closing the previous year." when I tried to run depreciation for first time for a company.
    In OAAR, it was noted that FY2008 already closed.
    Please advice.

    I understand you did the asset upload in 2008 and want to run the first depreciation run for 2009?
    In that case have a look in your take over data settings: SPRO:
    Financial Accounting / Asset Accounting / Asset Data Transfer / Parameters for Data Transfer /  Date Specifications / Specify Transfer Date/Last Closed Fiscal Year
    This should be 31-12-2008 (if the calendar year is the same as the fiscal year)

  • Dep Error:AA687-You can only post in new year after closing the previous year.

    Hi Experts,
    I need solution on error while posting dep. we have new co cd started operative from Jan -14 . So while doing dep posting run we are getting error "AA687-You can only post in new year after closing the previous year".
    I searched and got that Note 144441 need to implement.
    Let me know whether is it fine to go ahead or Is there any alternative solution.
    Also i want to know what need to to be done after implementing this note.
    please reply , its bit urgent.
    Regards
    Atul

    Hi Deepanshu,
    Also the FI period is also closed 2013 so in this case do i need to open the same , correct? for running dep posting along with OAAQ opening for AA.
    Or the note implementation will take care all. instead of running dep , opening closed period.
    pls suggest.
    Regards
    Atul

Maybe you are looking for

  • Error 4450 and error 4280

    Ok this is bad, I am new to ITunes I purchased a bunch of songs and transfered them to my Ipod fine, then I burned them to 3 cd's no problem. Saturday I wen to record an audio cd with 100 dollars worth of new songs and I got error 4450 out of my I/O

  • F-28 - Line item for customer charge off difference is going to dummy PC

    Hi In F-28 when we are making partial payments to customer and charging off the difference to the same customer account. The Charge off customer line item is going to dummy profit center after doing F.5D and 1KEK. Business dont want to use residual i

  • Underline in classical report

    HI, Im developing a classical report and want to underline a text which im doing thro sy-uline. However if i take a printout the underline appears as a separate row. Is there any way where i can get pure underline i.e. when taking a printout it will

  • ITS Admin page is not displaying but requesting download

    Hi, I am having a problem with my ITS, basically all the web pages function correctly, except the ITS admin page. I use the URL, but the response I get back is a dialog asking me to save the web page called !. After looking at this I think the script

  • Meeting Access Error

    When I enter the meeting room, Sometimes I got a "ValidateUserError.invalid.missing" Error. I' m running Connect 9.0 Anyone know what the problem is and how to fix it?