Too many static methods?

Hello,
I am using Oracle 9iAS 9.0.3. My app uses stateless session beans for data access.
Does anyone have opinions about using static methods in ejb's, specifically there impact on performance under high load? Can a bottleneck be caused by a call to a static method by multiple beans?

According to EJB Specification you cant declare your business methods static or final.
--Venky                                                                                                                                                                                                   

Similar Messages

  • Why there should not be many static methods.

    Why a java class should not have many static methods.How is memory managed in case of static methods.
    If a Utility class has static methods then we can use methods directly by class name but if we do not make the methods static then we can acess methods using object.How does it make the difference.I know that there remains a single copy of class variables/methods.But i want to know how class memory is managed and garbage collected.

    shobhit123 wrote:
    Why a java class should not have many static methods.How is memory managed in case of static methods.
    If a Utility class has static methods then we can use methods directly by class name but if we do not make the methods static then we can acess methods using object.How does it make the difference.I know that there remains a single copy of class variables/methods.But i want to know how class memory is managed and garbage collected.The reason to discourage static methods is stylistic rather than technical. It encourages object oriented thinking.
    Each loaded class is represented by a Class object, and associated with that it a block of memory for static fields. As with all such storage this block is, as viewed from code, rather like an array with one, or in the case of double or long values, two slots per field.
    Because the class loader maintains a map from FQN to Class this storage is only released if the class loader that loaded it becomes unreachable, which happens only in situations like the un-deployment of a web application or EJB.
    Local variables for static methods are allocated in a stack frame, just as with instance methods. There's really no significant difference there.

  • What's wrong with static methods?

    Answers on an postcard please.

    I think the point here is that sometimes people come from a procedural background (or maybe no background) and they start with main, and one static method leads to another. They reach a tipping point where they are reluctant to define non-static methods to a class because it's all static elsewhere. And static method can't access instance data, so their data becomes largely static as well. When the dust settles, they are programming procedually in Java. So too many static methods is a sign that you may be programming procedurally instead of doing OOP, but using static appropriately is still cool.
    And let's not get pedantic. What goes wrong if I make my String class's getLength method static?
    public final class MyString {
        private int length;
        public static int getLength(String s) {
            return s.length;
    }It's a misuse of static, but it doesn't break my design.

  • Static methods in multi-threaded environment

    Hi,
    I am wondering what happens when several threads try to access the same static method ?
    The static method is not synchronized.
    Will this create any performance issues ?
    The actual scenario is of a J2EE server, where several Session Bean instances try to access a static method in a utility class. Will some session beans have to wait till others are being serviced ?
    thnx n regards
    s giri

    thanx for replying.
    yes. the operations are thread-safe. we do not change the state of any object.
    but we make an rmi call to another application thru this static method.
    is it ok?
    Currently, my session bean has too many private methods - each calling the other application. Due to some quality metrics (a class must be restricted to 700 lines) we have to consider moving these private methods into some Helper class in the form of "public static methods". We have made many utility methods as static, but have some reservations abt doing a similar thing for these methods that call other application.
    regards
    Shivraman

  • What 's the advantage of static method.

    I think if a method is declared as static, the program should allocate some spaces for the method when the program start. However, I found many static method in an erp open source project. What make me confused is that it will cost many spaces.
    Perhaps they want to lose some spaces for speed???
    Can somebody answer my question.thanks!

    > I think if a method is declared as static, the
    program should allocate some spaces for the method
    when the program start. However, I found many static
    method in an erp open source project. What make me
    confused is that it will cost many spaces.
    Perhaps they want to lose some spaces for speed???
    Can somebody answer my question.thanks!
    To be sincere, I've never thought about performance cost when static methods are used. I decide to create and use them mainly whether I have the "feeling" that it will provide me benefits, in terms of designing. Yes, it's like a feeling. I am not able to explain you why or how I have this feeling, I'm not native in English language, so choosing the appropriate words to explain my ideas sometimes is hard to me. Besides. I admit that I am a little bit lazy in this moment, I don't want to search through some dictionary...;-).
    I think the more you develop your abilities and skills in java programming, the more you can feel, you can have this "feeling", and naturally you figure out in which situations using static methods is a better choice.

  • Static method - memory usage

    will an application containing many static methods use more memory than an application w/ less static methods? are there any performance or memory issues w/ using static methods?

    I totally disagree that one should let oop principles NOT performance dominate design. While you may have a point in 99.99% of applications, I am in the 0.01% where performance has forced me to implement some hard choices.
    If static is faster and you call that method millions of time you may have some real issues to face. Let's say you lose a microsecond on each call by going non-static. That means for 1x10^6 calls you've lost a second. Which may not seem like a lot, but in multi-threaded user apps such as servers, this is very significant.
    I'd argue that there shouldn't even be a method. In fact just expose the instance variables and access the data directly, or don't even have the class and just in-line. Or even better, jni. How about just write it in Assembler. Where to draw the line???
    Before rants occur, this is only important to do in critical sections of code. Not recommended where you can use well structured oop principles which are preferred.

  • DrawLine(...) method generates too many in[] instances

    My appplication performs very intensive painting (some kind of real time charts). It often invokes drawLine(...) method of Graphics class. Under profiler I have found out that it instantiate too many int[] (about 300000 every few seconds). Though garbage collector cleans these auxilary instances well, I don't like when it runs every time. How can I write my own drawLine method, which doesn't generate so many auxilary instances? By the way I need to draw only vertical or horizontal lines.

    Are you talking about drawing a grid?
    If so, 300000 sounds / few seconds sounds like there
    is something wrong.
    Suppose your screen is 1000x1000 and you are drawing
    lines every 10 pixels apart. That is 100 lines in
    both directions for 200 lines.
    200 lines and 4 ints per call is 800. Assume 100000 /
    second, then that means you are calling repaint 125
    times / second?
    I have about 40 - 50 JFrames, each of them contains panel, which performs painting. Repaint invokes 10-50 times every second for each JFrame. Each repaint draws 1200 lines every time it is invoked. And int[] instances are created inside Swing version of drawLine(...) method, at any case Borland Optimizeit 5.0 says so.
    If anything, I would make a temporary line object:
    private Line2D line = new Line2D.Double();
    public void paint(Graphics _g) {
    super.paint(_g);
    Graphics2D g = (Graphics2D) _g;
    for each horizontal and vertical line:
    line.setLine(x1, y1, x2, y2);
    g.draw(line);
    I've tried your code. Thanks a lot, but it generates too many int[] instances too:(.
    >
    Also, make sure you are not drawing lines outside of
    the area that needs to be repainted. That is, only
    draw a line if it would intersect the viewable
    rectangle of the panel, or even better if it
    intersects the getClipBounds() of the graphics
    object.

  • Static method,new thread performance question

    Hey guys i just have two questions about two methods used in many controllers/servlets in my app:
    1-what is the difference between calling a static method in a util class or a non static method (like methods dealing with dates i.e getting current time,converting between timezones), which is better ? 2-what is the difference between calling a method(contain too many logic like sending emails) in the controller directly or running this method in a different thread ?

    cs.student wrote:
    Hey guys i just have two questions about two methods used in many controllers/servlets in my app:
    1-what is the difference between calling a static method in a util class or a non static method (like methods dealing with dates i.e getting current time,converting between timezones), which is better ?Depends on the design. It's impossible to say straight why one way would be better than another. Programming isn't that straight forward.
    2-what is the difference between calling a method(contain too many logic like sending emails) in the controller directly or running this method in a different thread ?Threads can be run at the same time. So what you're asking is "what's the difference between doing one thing after another and doing two things at the same time".

  • Java.io.FileNotFoundException (Too many file open)

    Hi,
    I have an application wherein I have to open an XMl file, make amends to it and then write it back. It is possible that the same XML file be opened more than once. After processing lots of XMl files I get the following error:
    [java] java.io.FileNotFoundException: /nas/bansalp/app/databases/databases/IntActe_human_528_psimi.xml (Too many open files)
         [java]      at java.io.FileInputStream.open(Native Method)
         [java]      at java.io.FileInputStream.<init>(FileInputStream.java:106)
         [java]      at java.io.FileInputStream.<init>(FileInputStream.java:66)
         [java]      at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
         [java]      at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
         [java]      at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:653)
         [java]      at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)
         [java]      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
         [java]      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
         [java]      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
         [java]      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
         [java]      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
         [java]      at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
         [java]      at alliance.dps.Commons.makedocument(Unknown Source)Code for makedocument is as follows:
    public static Document makedocument(File file) throws Exception
      Document response = null;
      DocumentBuilder builder = null;
      try
         DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
         builder  = builderFactory.newDocumentBuilder();
         if (file==null)
          response = builder.newDocument();
         else
          response = builder.parse(file);
      catch(Exception e) { e.printStackTrace(); }
      return response;
    }Here also I am not explicitely opening any handle. parse method should close the file after creating a DOM tree.
    I would appreciate if someone could give me some directions as to what might be wrong.
    - Parit

    I'm finding that builder.parse(File) doesn't close the file. I now create a FileInputStream from the File and make sure I close it myself in a finally{} block.

  • Is it ok to mix some non static methods in ADFUtil and JSFUtils?

    Hi
    I am new to ADF 11g. I would like someone comfirm me whether it's ok to include some non static method into ADFUtil and JSFUtil class? how this would effect the performance, and connection pool instance (too many)etc..?
    thank you very much in advance.

    This doesn't make sense as you would break any existing code using these classes. you should leaf these classes alone and use a new utility class of your own to handle your non static stuff.
    Timo

  • Static methods in interface (Yes, once again!)

    I know there has been many questions about why static methods in interfaces are not allowed. I know it is forbidden by the JLS. But does anyone know the exact reason for this? Is it just a design issue or are there technical difficulties with allowing it?
    I can't think of any reason that it should be impossible to allow static methods in interfaces. I don't even think it would be very difficult to do. More importantly, it could probably be done without breaking existing code and existing JVMs (not too sure about the last one).
    So once again: Was the choice of not allowing static methods in interfaces a design choice or a technical choice?

    A better example of what you are suggesting is surely ...
    interface i {
        static void one();
    class a implements i {
        static void one() {
            // do something
    class b implements i {
        static void one() {
            // do something else
    }What would be the point of ever doing this?
    You cant call i.one() as the method doesn't exist without an instance of an implementing class.
    To actually ever be able to use that method you would effectively be casting an INSTANCE of a or b -> i. If you have an instance of an a or b then there is absolutely no reason for that method to be static.
    If you wanted to implement some sort of class (ie static) behaviour then class a could call its own internal static method from within the 'one' method.
    To get right to the point ... there isn't one. If it gets added to the language (and I can't see it in my wildest dreams) then Sun have lost their marbles, surely?
    Unless someone can give a good example of when it might be correct and useful to do so? I can't even see how it would be a convenience as it is completely unusable, no?

  • Getting java.io.IOException: Too many open files+ClassNotFoundException

    Dear All
    We have a web application deployed on Rational Application Developer 6.0 (Operating System is Windows 2000 professional) our users are randomly getting java.io.IOException: Too many open files+ClassNotFoundException when they click on some servlet or jsp link, but they are getting this error randomly for example when they click some link they may get these exceptions but refreshing page or clicking once again on same link executes servlet successfully.If anyone could help on this topic we will be grateful
    Thanks

    I think this these two exceptions are occuring in differrent environment
    java.io.IOException is occuring under heavy load to web server its stack trace is as follows:
    JSPG0225E: An error occurred at line: 2 in the statically included file: /SessionCheck.jsp
    JSPG0093E: Generated servlet error from file: /Admin/AdminInsuranceCertificates.jsp
    E:\WebSphere_6\AppServer\profiles\AUSECert\temp\centraNode04\server1\AUSECert\Vero.war\Admin\_AdminInsuranceCertificates.java:259: cannot access com.bplus.natmar.LoginDetails
    bad class file: E:\WebSphere_6\AppServer\java\jre\lib\core.jar(java/io/Writer.class)
    unable to access file: E:\WebSphere_6\AppServer\profiles\AUSECert\installedApps\centraNode04Cell\AUSECert.ear\Vero.war\WEB-INF\classes\com\bplus\natmar\LoginDetails.class (Too many open files)
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    (source unavailable)
    1 error
    ]: com.ibm.ws.jsp.JspCoreException: JSPG0049E: /Admin/AdminInsuranceCertificates.jsp failed to compile :
    this error always occurs in reference to logindetails class this clas is used to make a session check on different roles in our project for e.g., user having end user role should not be able to log in as a user having admin role
    we have included a sessioncheck.jsp in our every jsp page in this jsp we have simply used logindetails class as useBean and called its getresource() method
    above stacktrace is from our live application server
    while testing same project on our local system we are not getting too many open files exception but we are getting following ClassNotFoundException
    [11/30/05 17:11:42:797 EST] 0000004a SystemOut O SELECT count(*) as NoofRecs FROM resourcerolebindings WHERE ResourceName = 'mainEdit.jsp' and IsEndUser=1
    [11/30/05 17:12:50:891 EST] 000001eb SystemOut O SELECT count(*) as NoofRecs FROM resourcerolebindings WHERE ResourceName = 'InsuranceCertificates.jsp' and IsEndUser=1
    [11/30/05 17:17:40:828 EST] 0000008d SystemOut O AppURL is: http://www.VeroECert.com/Vero/indexU.jsp
    [11/30/05 17:17:58:141 EST] 0000008b SystemOut O SELECT count(*) as NoofRecs FROM resourcerolebindings WHERE ResourceName = 'InsuranceCertificates.jsp' and IsEndUser=1
    [11/30/05 17:20:41:703 EST] 00000034 ServletWrappe E SRVE0026E: [Servlet Error]-[com.servlet.UserHelpServlet]: java.lang.ClassNotFoundException: com.servlet.UserHelpServlet
         at com.ibm.ws.classloader.CompoundClassLoader.findClass(CompoundClassLoader.java(Compiled Code))
         at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java(Compiled Code))
         at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code))
         at java.beans.Beans.instantiate(Beans.java:202)
         at java.beans.Beans.instantiate(Beans.java:63)
         at com.ibm.ws.webcontainer.servlet.ServletWrapper$3.run(ServletWrapper.java:1384)
         at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java(Compiled Code))
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.loadServlet(ServletWrapper.java(Compiled Code))
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.initialize(ServletWrapper.java:1312)
         at com.ibm.wsspi.webcontainer.extension.WebExtensionProcessor.createServletWrapper(WebExtensionProcessor.java:84)
         at com.ibm.ws.webcontainer.extension.InvokerExtensionProcessor.handleRequest(InvokerExtensionProcessor.java:238)
         at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2841)
         at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220)
         at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204)
         at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java(Compiled Code))
         at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java(Compiled Code))
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java(Compiled Code))
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java(Compiled Code))
         at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java(Compiled Code))
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))
         at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
    this error is occuring on concurrent clicks suppose three users click on same button then it is possible that one user gets correct output while other users experience this exception
    Also one more point we are not using web.xml for calling servlets we are directly calling it giving its full path.
    Thanks

  • Router connection problems - DISH satellite receivers or too many devices?

    (Sorry about that - I thought I had broken the message up.)
    I'm having significant issues with my Linksys router timing out, and need help. I'll try to be as detailed as I can.
    I have the following:
    - Linksys WRT54G v3 wireless router I purchased off eBay 3-4 years ago. Using 128-bit WEP secirity. Even though the model says WRT54G, my Linksys setup page says I have a WRT54GL. Don't know if that's pertinent but thought I'd include the info)
    - HP desktop running Vista Home Premium
    - Gateway Solo laptop (circa 3Q 2002) running WinXP SP3, and also have WPC54G - Wireless-G Notebook Adapter
    - Gateway M275 Notebook running Windows XP Tablet Edition w/SP3, internal wireless card
    - Linksys WRE54G Wireless Range Expander, v3
    My broadband internet connects to my cable modem, which then runs via ethernet to my router. I have my desktop connected to my router via (wired) ethernet cable (port 1), and the two laptops connect wirelessly. All three computers on my network run just fine and have had no connection issues until I had two (2) DISH satellite receivers installed this past Friday.
    Prior to installation, I knew I would need the two receivers hooked up to my network via ethernet cable. Since one receiver was in the same room as my router, it was easy to run an ethernet cable from my router to the receiver (port 2). I had a challenge with the upstairs receiver, because I didn't have a direct connection, and wasn't sure how to wire it. So, I used my range expander by plugging in the expander into a nearby outlet, then connecting the receiver to the expander via ethernet cable.
    I had some issues getting a good signal, and did some troubleshooting but made it work. Now I had five devices connected to my router: two with a wired ethernet cable and three wirelessly.
    I started having connection timeouts within about 3-4 hours of satellite [receiver] installation. All of the sudden I couldn't connect to the internet on ANY device; both laptops couldn't connect wirelessly, my desktop couldn't connect, and the receivers were telling me my connection was bad. I checked modem but there were no issues. Still, I unplugged the power cable from the modem for a minute, then reconnected - still no internet. I called my cable company to have them troubleshoot the modem, but they pinged it several times & got positive results - still no internet, so I ruled the modem out.
    I tried using the Windows connection troubleshooter to repair the problem, and got a DNS error message (which I don't know how to fix). I decided to unplug my router for 10-15 seconds, then plug back in - that got my internet connection going again. That lasted a couple hours & then failed. I unplugged the router again (is that a soft reset or a power cycle?), then reconnected & was able to connect to the internet. This happened a few more times over the weekend, and finally I decided the expander might be the issue (both DISH and Linksys tech support was not very helpful).
    I found a way to wire my second receiver via ethernet cable (port 3), so now I had three wired devices, and two wireless devices. I thought this would fix the problem; it didn't, but at least I learned how to wire CAT5 cable. So I got that going for me... which is nice.
    I plugged the ethernet cable directly from my modem to my desktop to test the timeout, but had no issues - the modem just wasn't the problem.
    I was getting some IP address conflicts on my Norton Inernet Security, so I uninstalled that from my desktop, disconnected the power from the modem, disconnected the power from the router, shut down all devices, reset the IP addresses on the receivers, deleted the wireless connection from the laptops, shut down the desktop, and just left the whole mess alone for half a day. Then I reinstalled the Norton Internet Security, connected my wired devices, plugged the modem in, plugged the router in, reset my security, connected wirelessly with my laptops.
    Within an hour my connection timed out.
    Trying to chat with tech support wasn't feasible, as my connection kept going out. A guy at work said I shoudl ping my IP address, and let it repeat until my connection goes out. So I unplugged the router and plugged it back in to get an internet connection, the opened a cmd prompt and typed
    ping 192.168.1.1 -t
    I left it alone for a few hours, and when I came back, my internet connection was down, but I was still getting active pings - no problems there.
    At this point I thought I had done everything except replacing my router (which I'm still tempted to do), but I called my broadband provider to see if there was anything they could do. One of the techs said I had too many devices connected to the internet, but I thought these routers were supposed to handle dozens of devices?
    I finally called Linksys Tech Support and had a conversation for 90 minutes. We went through all the steps of unplugging the the modem, router & all connected devices, resetting the router, etc, etc. The only thing different he did was had me change my security from WPA to 64-bit WEP, and added passwords for DNA1 and DNS 2 (same password for each).
    That was at 1:30am last night, and when I woke up to check my connection this morning, it was still connected. I have to check it again when I get home, but I'm wondering if I should just be prepared to get another router (and if so, any recommendations), or if there's something I'm still not doing that could resolve my issue - if I still have connection losses.
    Also, I'm concerned about the security thing. If changing from WEP 128 or WPA to WEP 64 fixed my problem, I'm not sure I feel completely protected from intrusion - isn't that pretty much the least amount of security I can have (without forgoing it altogether)??
    Finally, I've read a few threads suggesting possibly changing to static IP from DHCP; however, my satellite receiver installation documentation specifically advises against this for the receivers.
    Anyway, I would very much appreciate some help.
    Message Edited by CKdoubleU on 10-01-2008 08:43 AM

    First please break that long text into separate paragraphs. No one wants to read one long runon sentences
    With Knowledge… Impossible means nothing.
    Credentials
    Computer experience: 11 years
    Cisco networks experience: 8 years
    Network administrator: 6 years
    N.E.T. networks experience: 6 years
    Linksys networks experience: 6 years
    Recent additions: A+ | Networks+ | Linux+ | Security+

  • Too many connections - even after closing ResultSets and PreparedStatements

    I'm getting a "Too many connections" error with MySQL when I run my Java program.
    2007-08-06 15:07:26,650 main/CLIRuntime [FATAL]: Too many connections
    com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Too many connections
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:921)
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:812)
            at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3269)
            at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1182)
            at com.mysql.jdbc.Connection.createNewIO(Connection.java:2670)I researched on this and found out that I wasn't closing the ResultSet and the PreparedStatement.
    The JDBC connection is closed by a central program that handles connections (custom connection pooling).
    I added the code to close all ResultSets and PreparedStatements, and re-started MySQL as per the instructions here
    but still get "Too many connections" error.
    A few other things come to mind, as to what I may be doing wrong, so I have a few questions:
    1) A few PreparedStatements are created in one method, and they are used in a 2nd method and closed in the 2nd method
    does this cause "Too many connections" error?
    2) I have 2 different ResultSets, in nested while loops where the outer loop iterates over the first ResultSet and
    the inner loop iterates over the second ResultSet.
    I have a try-finally block that wraps the inner while loop, and I'm closing the second ResultSet and PreparedStement
    in the inner while loop.
    I also have a try-finally block that wraps the outer while loop, and I'm closing the first ResulSet and PreparedStatement
    in the outer while loop as soon as the inner while loop completes.
    So, in the above case the outer while loop's ResultSet and PreparedStatements remain open until the inner while loop completes.
    Does the above cause "Too many connections" error?
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The following is relevant sections of my code ( it is partially pseudo-code ) that shows the above 2 cases:
    init( Connection jdbcConnection ){
       String firstSQLStatement = "....";
       PreparedStatement ps1 = jdbcConnection.prepareStatement( firstSQLStatement );
       String secondSQLStatement = "....";
       PreparedStatement ps2 = jdbcConnection.prepareStatement( secondSQLStatement );
       String thirdSQLStatement = "....";
       PreparedStatement ps3 = null;
       ResultSet rsA = null;
       try{
            ps3 = jdbcConnection.prepareStatement( thirdSQLStatement );
            rsA = ps3.executeQuery();
            if( rsA.next() ){
                   rsA.getString( 1 );
       }finally{
            if( rsA != null )
                   rsA.close();
            if( ps3 != null )
              ps3.close();
       //Notice, how ps1 and ps2 are created here but not used immediately, but only ps3 is
       //used immediately.
       //ps1 and ps2 are used in another method.
    run( Connection jdbcConnection ){
         ResultSet rs1 = ps1.executeQuery();
            try{
               while(rs1.next()){
                    String s = rs1.getString();
                    ps2.setString(1, s);
              ResultSet rs2 = ps2.executeQuery();
                    try{
                   while(rs2.next()){
                        String s2 = rs2.getString();
                    }finally{
                   if( rs2 != null )
                     rs2.close();
                   if( ps2 != null )
                     ps2.close();
         }catch( Exception e ){
              e.printStackTrace();
         }finally{
            if( rs1 != null )
                  rs1.close();
               if( ps1 != null )
                  ps1.close();
    //Notice in the above case rs1 and ps1 are closed only after the inner
    //while loop completes.
    }I appreciate any help.

    Thanks for your reply.
    I will look at the central connection pooling mechanism ( which was written by someone else) , but that is being used by many other Java programs others have written.
    They are not getting this error.
    An addendum to my previous note, I followed the instructions here.
    http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html
    There's probably something else in my code that is not closing the connection.
    But I just wanted to rule out the fact that opening a PreparedStatement in one method and closing it in another is not a problem.
    Or, if nested ResultSet loops don't cause the problem.
    I've read in a few threads taht "Too many connections" can occur for unclosed RS and PS , and not just JDBC connections.

  • Too many open socket connections causing ColdFusion to crash?

    I’m currently working on an e-commerce site which sends and receives information to/from the client’s order management system via XML over a TCP/IP socket.  It uses a very old java-based custom tag called CFX_JSOCKET (which appears to have been written in 2002) to open the socket, send the data, and get the response.  The code that calls the custom tag and sends/receives data from the OMS pre-dates my working on the site, but its always worked, so I haven’t paid it much attention.
    Back in the summer of 2009 we started experiencing issues with ColdFusion (v.7 on Window 2003 at the time) locking up on a more and more frequent basis, until it ultimately became a daily issue.  After extensive research we narrowed the issue down to the communication between the web server and our client’s order management server.  It seemed the issue with ColdFusion hanging was either related to there being too many connections open, or to these connections hanging and resulting in dead threads.  This an educated guess based on a blog post I’d seen online, not actual monitoring of either CF or the TCP/IP connections.  As soon as we dialed back the timeout on the CFX_JSOCKET tag from 20 seconds to 10, the issue disappeared, so we left it at that and moved on.
    Fast forward to this January. The site is hosted at a new location, on a 64-bit Windows 2008 box running ColdFusion 9.  Over the years traffic on the site has continued to grow.  The nature of the clients business means that August and January are their business times of the year (back to school for college kids) and in January ColdFusion once again started locking up on an almost-daily basis.  
    One significant difference is that the address cleansing software that previously ran on the box and was used to verify shipping addresses is not available for 64-bit, so when we moved to the new server last summer, that task was moved to the client’s order management software and handled via XML like all other interaction with that system. However, while most XML calls to that server (order input, inventory check, etc) take under a second to complete, the address cleansing call regularly takes over 5 seconds to return data, and frequently times out. 
    Once we eliminated the address cleansing call from the checkout process, ColdFusion once again stopped locking up regularly.  So it appears that once again it’s the communication between the web server and the order management server that’s causing problems. We currently have that address cleansing call disabled on the web site in order to keep ColdFusion from crashing, but that’s not a long term solution.
    We don’t have, nor can I find online, the source code for the CFX_JSOCKET custom tag, so I decided I’d write some CF code utilizing the java methods to open the socket, send the data, get the response, and close the connection.  My test code is working fine (under no load).  However, in trying to troubleshoot an issue I had with it, I started monitoring the TCP/IP connections using TCPView.  And I noticed that all the connections to the order management server, whether opened via the custom tag or my new code, remain open in either a TIME_WAIT or FIN_WAIT2 status for well over 2 minutes, even though I know for a fact that my new code is definitely closing the connection from the web server side. 
    They do all close eventually, but I’m wondering 1. Why they’re remaining open that long; 2. Is that normal; and 3. If all these connections remaining open could be what’s causing ColdFusion to choke. 
    Does this sound plausible?  If so, does anyone have any suggestions/recommendations about how to fix it?  My research seems to indicate this might be a matter of the order management system not closing the connection on its end, but I’m in way over my head, and before I go to client and tell them it’s their OMS causing the issue, I need to feel a little more confident that I’m on the right track. 
    Any help or advice would be very greatly appreciated.  And thanks for taking the time to read through my long-winded explanation of the problem.
    Set-up details:
    ColdFusion Version: 9,0,0,251028  Standard 
    Operating System: Windows Server 2008 
    Java Version: 1.6.0_14 
    Java VM Name: Java HotSpot(TM) 64-Bit Server VM 
    Java VM Version: 14.0-b16 
    Thanks,
    Laurie

    Hi Laurie,
    Not aware of custom tag called CFX_JSOCKET. I guess the process you described very well is consuming a resource then you are getting a problem. Trick is what parameter to adjust. Perhaps you are running out of one the threads in CFadmin > Server Settings > Request Tuning.
    I expect if you enable CF Metrics logging where you can log the threads and other resources then you can find out which parameter needs adjusting. Let me know if you want some details on enabling CF Metrics. Perhaps others will have much better idea than me and help without the overhead of logging.
    The other interesting thing is you are using CF9.0.0. Do you have some reasons for not being on updater1 CF9.0.1?
    HTH, Carl.
    PS I posted before however seems to have gone, just hope does not come back and then I have posted twice.

Maybe you are looking for

  • One computer, 2 iTunes accounts

    Many hours spent trying to figure this out. We have one computer with internet access. I already have an iTunes account and have used it often. Another member of the family who has access to the same computer, wants a separte LIBRARY. I have opened 2

  • How do I play games on the new version of IPad?

    Hi, I want to know how I'm going to play games on the new version. Best regards Johan

  • Spry, Shadowbox, and IE...damnit.

    Let me first off say that I am new to XML, SPRY, and Javascript. With that said, I've stumbled my way through. But now I am stumped. I am having a problem with Shadowbox and Spry working nicely together. Here is the page in question: www.discgotech.c

  • Does row_number() returns different result set every time?

    Hi, I have a query somewhat like the example: select /*+ parallel (ftstm,4) */ ftstm. term, sum(ftstm.revenue) revenue, sum(ftstm.searches) searches, row_number() over (order by sum(ftstm.revenue)desc) as depth_rank from fact_terms group by ftstm.ter

  • Changing L&F for the JFileChooser

    Hi, take a look at Sun's bug #4711700. Using the Windows L&F, sometimes the JFileChooser throws a NullPointerException when the constructor is called. Apparently, the bug is related to retrieving Windows system icons to be shown in the dialog, so it'