Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4018086
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:56:23+00:00 2026-05-20T09:56:23+00:00

Had I looked into the Java SE6 documentation sooner on Context and InitialContext, I

  • 0

Had I looked into the Java SE6 documentation sooner on Context and InitialContext, I would’ve seen that there is a close() method for each.

So now I wonder, do I need to call the close() method on the Context/InitialContext objects?

Here is a snippet of my typical servlet code and how the Context/InitialContext object is used.

public class MyTypicalServlet extends HttpServlet {     

    //thread safe
    DataSource ds;
    String FilePath;    

public void init(ServletConfig config) throws ServletException {

    super.init(config);
    try {
        final Context ctx = new InitialContext();
        ds = (DataSource) ctx.lookup("java:comp/env/jdbc/myDB");

        FilePath = getServletContext().getInitParameter("FilePath");                

    } catch (NamingException e) {
        throw new ServletException("Unable to find datasource: " + e.getMessage(), e);
    }
}               

    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    {
        doPost(req,res);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    {       

    //...a bunch of code
    }

}//class        
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:56:23+00:00Added an answer on May 20, 2026 at 9:56 am

    It’s a good habit to get into. For example, I always make sure to close my InputStream classes, even if I’m using a ByteArrayInputStream, where the close() method is a no-op. That way, if I change it to some other implementation later, it’s one less thing to have to change as well.

    Same case here – if you call close(), you’ll be more compatible with any JNDI implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a discussion with some colleagues mentioning that there are not too many
I had the idea of a search engine that would index web items like
I would like to wrap a java program into a windows service with C#
I had an idea for an app that would require me to implement these
Has anyone looked at Yahoo's ASTRA ? It's fairly nifty, but I had some
I had to delete all the rows from a log table that contained about
I have a java program that runs a bunch of queries against an sql
I am currently working on some Java code that has a lot of ActionListeners
Had an interesting discussion with some colleagues about the best scheduling strategies for realtime
Had a coworker ask me this, and in my brain befuddled state I didn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.