RE: JDBC try/catch Pitfall ***MUST READ***

2002-04-09 Thread Shane Whitehead

I personally follow the old school of thought, 1 entry, 1 exit...while this
was probably intended to describe the entry/exit points of a program itself,
I use this same idea when coding...rather then returning in the middle of a
block of code, I generally try and return at the end, while this can
sometimes increase the complexity of the code, it generally makes it easier
to read and follow...

However, I think you problem relates more to what's going on in the final
block then anywhere else...each close statement should be trapped in their
own try/catch block (as mentioned before), while this increases the amount
of code, it ensures that each statement can be called...

Shane

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Scott Farquhar
Sent: Wednesday, 10 April 2002 08:16 am
To: Orion-Interest
Subject: Re: JDBC try/catch Pitfall ***MUST READ***


This site demonstrates the pitfalls with using returns & finally:

http://www.cs.arizona.edu/sumatra/hallofshame/

It seems like this behaviour is not specified by the Java Language
Specification.

Cheers,
Scott

Greg Davis wrote:
> This deals with try/catch blocks and finallys. I always believed that "no
> matter what" a finally block is always called.  While this seems to remain
> true, it does not seem to necessarily properly call the code within the
> block.  In the section below I have some code and explanation of how a
> finally gets called, but does not execute the code within.
>
> There seems to be an issue with closing a JDBC connection if a method
> returns in the middle of the try/catch block.  It seems to call the
finally,
> but does not close the connection.  It does seem to call static methods
like
> System.out.println() perfectly fine.  I don't know if it being static has
> anything to do with it.  I haven't researched it too far since it was
really
> hard to find.  First off you have to have a Factory like a ConnectionPool
> that spawns out inscances of an object for other classes to use. Then it
> must need to have the user close it's connection at some point so the
> Factory can control resources. The only example I really have on hand is a
> JDBC connection pool in a J2EE app server.  This is where the problem
occurd
> for us.  If the methods "returns" are moved outside the try/catch block,
the
> Connection.close() happens properly and the ConnectionPool does not
> complain.
>
> I realize the getColumnClose() is the better way to implement the code
> ayway, but I wanted to show everyone this problem in case they
accidentally
> do it in their code somewhere.  Any returns in the try or catches seemed
to
> make the finally not be properly executed. I seem to remember some wierd
> rule about this at JavaOne last year, but my head is still racing from all
> that information. :-)
>
> Any comments?
>
> package test;
>
> import java.sql.*;
> import javax.sql.DataSource;
> import javax.naming.*;
>
> /**
>  * Title: TryCatchTest
>  * Description: This is a test application for try/catch problem.  If
> using
>  * a Connection Pool in JDBC and you try to "return" a value within a
> try/catch
>  * that is inside a method, the finally of that try/catch is not
completely
> run.
>  * It seems to go through the finally(I.E. Sytem.out.println() works, but
> the
>  * Connection.close() is either never called or not executed.  If the
> "return"
>  * is moved to the outside of the catch block, the connection is properly
> closed.
>  * 
>  * We found this because a J2EE server which had a connection pool was
> telling
>  * us we were not closing our connections.  I dn't know if there is some
> rule that
>  * when a "return" has been called only static methods or something like
> that can
>  * be called.
>  * Copyright: Copyright (c) 2002
>  * Company: Western Electronics 
>  * @author Greg Davis
>  * @version 1.0
>  */
>
> public class TryCatchTest
> {
>   Context jndiContext;
>
>   public TryCatchTest()
>   {
> try
> {
>   jndiContext = new InitialContext();
> }
> catch(NamingException ne)
> {}
>   }
>
>   public String getColumnNoClose()
>   {
> Connection conn = null;
> PreparedStatement ps = null;
> ResultSet rs = null;
> try
> {
>   String sql ="SELECT table_name FROM sequence";
>   conn
> =((DataSource)jndiContext.lookup("jdbc/mySourceDS")).getConnection();
>   ps = conn.prepareStatement(sql);
>   rs = ps.executeQuery();
>   if(rs != null && rs.next())
>   {
> //This return causes the ?non-static? code within the finally to
not
> to be run.
> return rs.getString("table_name");
>   }
>   //same here, the finally ?non-static? code is not called.
>   return null;
> }
> catch(NamingException ne)
> {
>   //same here, the finally ?non-static? code is not called.
>   return null;
> }
> catch(SQLException sqle)
> {
>   sqle.printStackTrace();
>   //The same problem occurs here.  The finally

RE: Orion EJB container and SSL

2002-04-05 Thread Shane Whitehead

I'd love to hear more on the subject to!

Shane

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Sorin Pop
Sent: Friday, 5 April 2002 07:31 pm
To: Orion-Interest
Cc: Pop Lucian Marius
Subject: Fw: Orion EJB container and SSL


Hey,

is there anybody out there who can tell me something about this?! I've sent
this  more than a week ago, and I got no feedback whatsoever. If I'm talking
bullshit (e.g the question is stupid or something like that), at least tell
me _that_ somebody! But, please, somebody say something to it...

- Original Message -
From: "Sorin Pop" <[EMAIL PROTECTED]>
To: "Orion-Interest" <[EMAIL PROTECTED]>
Sent: Friday, March 29, 2002 3:21 PM
Subject: Orion EJB container and SSL


> Is it possible to use SSL with the EJB container of the Orion server? For
> example the client is a standalone Java application that makes only
RMI-IIOP
> calls to EJB-s (no JSP, no servlets, no HTML involved) in the EJB
container.
> And I want to do this with security in mind, for example using SSL. Is it
> possible? (I read that it is possible to use SSL with simple RMI
> applications, or with a web application in the Orion server, but I would
> like to use Orion server's EJB container only...).
>
>






RE: idea=$395.00USD was: RE: Java IDE?

2002-03-24 Thread Shane Whitehead

I believe it comes down to the individual requirements of the developer.
You can discuss it till your blue in the face, but if it doesn't fill
comfortable, then, like most users, you won't use it.  Go with what feels
right for you and don't be to swayed with what other people think.

I've been lucky that most of the places I've worked at have allowed me to
use the editor of my choice and personally I prefer netbeans, but that's
more to do with the fact that I was required to use at Uni and at the time
their was only a hand full of editors and all of them (except Netbeans)
seemed to use a propriety VM - but that's ancient history.

Most of the experience is in Swing and I hand code 99% of all my UI, I've
yet to meet a UI designer that can cut it.

Essentially, try a few, find the one you like and hope it's not to
expensive, but at the end of the day, if you can't live without it, you're
going to have to pay for it...

Good hunting!

Shane





RE: java.lang.OutOfMemoryError

2002-03-12 Thread Shane Whitehead

The amount of memory in the box won't make much difference if the VM is not
configured to use it...It's default settings are rather low, you'll need to
check the startup script to see how much stack space it's putting
aside...this is also related to performance issues as the VM will take
longer to load with a large initial stack, but run more smoothly because
it's not stopping to increase the size of the stack...

Not sure about the other problem though.

Shane

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of mars
Sent: Tuesday, 12 March 2002 06:16 pm
To: Orion-Interest
Subject: java.lang.OutOfMemoryError


Dear orion user :

I got a problem I have a Orion Appcation Server Run on Linux
run the http service and https service then after a few hours
I got the message in server.log
*--
java.lang.OutOfMemoryError
<>
*--
and the https service down but http service still running
is the memory low to use or any possable cause?

!!!my server have 1GB Ram!!!