× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I ran into the very same thing. 
My connections had to be session specific, not so much user specific, 
but this should achieve the same thing.
By implementing HttpSessionBindingListener in your connection class, 
you can bind the connection to the user specific session, when the 
session times out, the connection will be closed. 

With the connection class bound the session, from the request.session 
class, 
you can get your instance of the class and the user specific connection. 

This was the only way I could guarantee that my connections were close 
after the user closed the browser..

Hope this makes sense. 


I call this method when I want to bind the connection:

    /** This method gets a connection to the as400 and saves it to the 
session. 
     * @param session  HTTPSession
     * Returns True if successful, false on fail.
     */
    private boolean getAS400conn(HttpSession session){
 
        try{ 
            //get the parms from the configuration file (web.xml)
            ServletContext context = getServletContext();
            String sysName = context.getInitParameter("as400System");
            String userID = context.getInitParameter("as400UserID");
            String passWord = context.getInitParameter("as400PWord");
 
            //get the connection
            as400Conn thisAS400conn = new as400Conn(sysName, userID, 
passWord); 
 
            //bind the connection to the session
            session.setAttribute("conAS400", thisAS400conn); 
 
            //successful, return true
            return true;
        }
        catch (Exception e) {
            System.out.println("Error in getting connection:" + 
              e.getMessage());
            //unsuccessful, return false
            return false;
        }


**********************************************************************************
Here is the connection class that is bound:


public class as400Conn implements HttpSessionBindingListener {
 
    /** The AS400 system name that will be connected to. */
    private String systemName; 
 
    /** The user name used for the connection. */
    private String userID;
 
    /** The password for the user. */
    private String passWord;
 
    /** The AS400 connection object. */
    private AS400 as400;
 
    /** The AS400 command object, used to call commands. */
    private CommandCall cmd;
 
    /** The AS400 program object, used to call programs. */
    private ProgramCall pgm;
 
 
    /** Creates a new instance of as400Conn. 
     *      <p><b>theSystemName</b> = the as400 system to connect to. </p>
     *      <p><b>theUserID</b> = the user name used for the connection. 
</p>
     *      <p><b>thePassWord</b> = the password for the user. </p> 
     */
    public as400Conn(String theSystemName, String theUserID, 
      String thePassWord) { 
 
        this.systemName = theSystemName;
        this.userID = theUserID;
        this.passWord = thePassWord;
    } 

    /** Called when this class is bound to a session. 
     *  <p>This method handles the connections to the as400. If any errors
     *  were encountered, the error string will not be null..</p>
     */
    public void valueBound(javax.servlet.http.HttpSessionBindingEvent sbe) 
{
        boolean x;
        try {
//            System.out.println("as400Conn in valueBound");
 
            if (openAS400() != true){
                throw new Exception("Errors opening AS400");
            }
            //System.out.println("after openAS400");
 
            if (openCMD() != true){
                throw new Exception("Errors opening CMD");
            }
            //System.out.println("after openCMD");

            if (openPGM() != true){
                throw new Exception("Errors opening PGM");
            }
            //System.out.println("after openPGM"); 
        }
        catch (Exception e) {
            System.out.println("Error in as400Conn.valueBound: " + 
              e.getMessage());
        }
    }
 
    /** Called when this class is unbound from a session. 
     *  <p>This could happen when the class object is removed 
     *  from the session or when the session is going to terminate. </p>
     */
    public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent 
sbe) {
 
        System.out.println("in valueUnbound 
*********************************");
        try{
 
            System.out.println("Session ID: " + sbe.getSession().getId());

            String jobNumber = cmd.getServerJob().getNumber();
            System.out.println("cmd jobnumber: " + jobNumber); 

            as400.disconnectAllServices();
        }
        catch(Exception e){
            System.out.println("Error in as400Conn.valueUnbound: " + 
              e.getMessage()); 
        }
    }
 
    /** Opens a connection to the AS400 and saves it in the as400 object. 
*/
    private boolean openAS400(){
 
        try {
            //System.out.println("In openAS400");
 
            as400 = new AS400(); 
            as400.setSystemName(systemName);
            as400.setUserId(userID);
            as400.setPassword(passWord); 
 
            as400.connectService(AS400.COMMAND); 
 
            return true;
        }
        catch(Exception excpt){
            System.out.println("Error in as400Conn.openAS400: " + 
              excpt.getMessage());
            return false;
        } 
    }
 
    /** Opens and saves a command object associated to the as400 object. 
*/
    private boolean openCMD(){
 
        try {
            //System.out.println("In openCMD"); 
 
            cmd = new CommandCall(as400);
            cmd.setThreadSafe(true); 
 
//            String jobNumber = cmd.getServerJob().getNumber();
//            System.out.println("cmd jobnumber: " + jobNumber);  
 
            return true;
        }
        catch(Exception excpt){
            System.out.println("Error in as400Conn.openCMD: " + 
              excpt.getMessage());
            return false;
        } 
    }
 
    /** Opens and saves a program object associated to the as400 object. 
*/
    private boolean openPGM(){
 
        try {
//            System.out.println("In openPGM"); 
 
            pgm = new ProgramCall(as400);
            pgm.setThreadSafe(true);
 
//            String jobNumber = pgm.getServerJob().getNumber();
//            System.out.println("pgm jobnumber: " + jobNumber); 
 
            return true;
        }
        catch(Exception excpt){
            System.out.println("Error in as400Conn.openPGM: " + 
              excpt.getMessage());
            return false;
        } 
    } 
 
    /** Returns the AS400 object. */
    public AS400 getAS400(){
        return this.as400;
    }
 
    /** Returns the AS400 command call object. */
    public CommandCall getCmd(){
        return this.cmd;
    }
 
    /** Returns the AS400 program call object*/
    public ProgramCall getPgm(){
        return this.pgm;
    } 
}


Lance King
Programmer/Analyst
Raynor Garage Doors
Dixon IL. 61021



Ashish Kulkarni <kulkarni_ash1312@xxxxxxxxx> 
Sent by: java400-l-bounces@xxxxxxxxxxxx
02/05/2004 11:44 AM
Please respond to
Java Programming on and around the iSeries / AS400 
<java400-l@xxxxxxxxxxxx>


To
Java Programming on and around the iSeries / AS400 
<java400-l@xxxxxxxxxxxx>
cc

Subject
RE: AS400 and JDBC Connection in QUSRWRK subsystem for ever






Hi
yes i need one AS400 Connection for each user, for
JDBC i am using Connection pooling and create 1
connection for many users, but for AS400 i need one
connection for each user atleast,
Since the RPG program needs  user id for some security
purpose, so i cannot use a generic user id and
password for connection pooling as i can use in JDBC
Connection
So i will end up with one connection for each user,
but the advantage is that the one connection will be
used when the user logs off and login again and again
But i assumed this AS400 connections will die after a
while, but it is not happening
Also my main problem is that the activation groups are
never killed and so files are open and locked
So any suggestions on it

Ashish
--- Colin Williams <colin.williams@xxxxxxxxxxxx>
wrote:
> Ashish,
> 
> Sorry, I assumed you were doing database pooling
> using the datasources in
> websphere
> 
> Maybe im missing something, but if your using
> specific user ids and
> passwords, do you need to pool the connections, 
> Or is one user doing multiple things at the same
> time.
> 
> Arent you going to end up with a lot of pools, at
> least 1 pool for each
> user?
> 
> Cheers
> Colin.W
> 
> -----Original Message-----
> From: Ashish Kulkarni
> [mailto:kulkarni_ash1312@xxxxxxxxx] 
> Sent: 05 February 2004 16:19
> To: Java Programming on and around the iSeries /
> AS400
> Subject: Re: AS400 and JDBC Connection in QUSRWRK
> subsystem for ever
> 
> 
> Hi
> I dont set any parameters
> this is what i do
> // to create a new connection
>  AS400ConnectionPool testPool = new
> AS400ConnectionPool();
> 
>  AS400 as400 = testPool.getConnection(system,
> userid,password);
> //to get connection and
>  testPool.returnConnectionToPool(as400);
> //to return the connection to pool after user uses
> it,
> 
> 
> is there a better way of doing it, i have to use
> user
> specific connection and not use a generic user id
> and
> password,
> 
> Ashish
> 
> 
> --- Colin Williams <colin.williams@xxxxxxxxxxxx>
> wrote:
> > what properties have you got set for the
> connection
> > pool, im sure there is
> > one that relates to idle connnections, and the
> > length of time before they
> > are cleaned up
> > 
> > cheers
> > colin.W
> > ----- Original Message -----
> > From: "Ashish Kulkarni"
> <kulkarni_ash1312@xxxxxxxxx>
> > To: "Java Programming on and around the iSeries /
> > AS400"
> > <java400-l@xxxxxxxxxxxx>
> > Sent: Wednesday, February 04, 2004 10:38 PM
> > Subject: Re: AS400 and JDBC Connection in QUSRWRK
> > subsystem for ever
> > 
> > 
> > > Hi
> > > I am using JTOpen4.1 , which i downloaded from
> web
> > and
> > > i am using websphere on windows 2000 and not on
> > AS400,
> > > My problem is that the connection is returned
> and
> > then
> > > the same connection is used, but may be after 24
> > hours
> > > a new connection is created , but the old one is
> > not
> > > removed from the QUSRWRK susbsytem
> > > it remains there for ever
> > > Ashish
> > > --- Colin Williams <colin.williams@xxxxxxxxxxxx>
> > > wrote:
> > > > Ashish,
> > > >
> > > > which version of JTOpen are you using. I have
> > > > recently run into a very
> > > > similar problem.
> > > >
> > > > I was using websphere datasources/connection
> > pooling
> > > > using
> > > > AS400JDBCConnectionPoolDataSource from jtopen
> > 3.3.
> > > >
> > > > What I found was that the application that I
> had
> > > > written died very quickly
> > > > because every time you accessed a jsp it was
> > > > creating a new connection in
> > > > the pool, rather than using an existing pooled
> connection, so very 
> > > > quickly ran out of connections.
> > > >
> > > > When I installed the latest jtopen on my PC,
> > 4.2,
> > > > the pooling appeared to
> > > > work correctly. The connections were returned
> to
> > the
> > > > pool, and the next time
> > > > the jsp was accessed, it correctly used an
> > existing
> > > > connection, rather than
> > > > trying to create a new one.
> > > >
> > > > We now need to apply the latest cum PTF to get
> > this
> > > > installed in the jt400
> > > > on the as400, and hopefully that should fix
> the
> > > > problem.
> > > >
> > > > cheers
> > > > Colin.W
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "Ashish Kulkarni"
> > <kulkarni_ash1312@xxxxxxxxx>
> > > > To: <java400-l@xxxxxxxxxxxx>
> > > > Sent: Wednesday, February 04, 2004 9:07 PM
> > > > Subject: AS400 and JDBC Connection in QUSRWRK
> > > > subsystem for ever
> > > >
> > > >
> > > > > Hi
> > > > > I have web application in which i am using
> AS400ConnectionPool 
> > > > > and
> > AS400JDBCConnectionPool
> > > > for
> > > > > AS400 and JDBC Connections,
> > > > > But i see about 5-6 connections for each
> user
> > in
> > > > > QUSRWRK
> > > > > and they seem to be there for ever. They are
> > never
> > > > > removed from the system untill i restart the
> > web
> > > > > application server or IPL the AS400,
> > > > > What may be the reason, why is a new AS400
> > > > connection
> > > > > of JDBC connection created when one is
> > existing,
> > > > > I take care or returning all the connections
> > back
> > > > to
> > > > > pool after each time i use them in program.
> > > > > It seems that one connection is created
> daily
> > but
> > > > the
> > > > > old one is still sitting in system
> > > > > How can I manage and solve this problem
> > > > > Ashish
> > > > >
> > > > >
> > > > > =====
> > > > > A$HI$H
> > > > >
> > > > > __________________________________
> > > > > Do you Yahoo!?
> > > > > Yahoo! SiteBuilder - Free web site building
> > tool.
> > > > Try it!
> > > > > http://webhosting.yahoo.com/ps/sb/
> > > > >
> > _______________________________________________
> > > > > This is the Java Programming on and around
> the
> > > > iSeries / AS400 (JAVA400-L)
> > > > mailing list
> > > > > To post a message email:
> > JAVA400-L@xxxxxxxxxxxx
> > > > > To subscribe, unsubscribe, or change list
> > options,
> > > > > visit:
> > > >
> >
> http://lists.midrange.com/mailman/listinfo/java400-l
> > > > > or email: JAVA400-L-request@xxxxxxxxxxxx
> > > > > Before posting, please take a moment to
> review
> > the
> > > > archives
> > > > > at http://archive.midrange.com/java400-l.
> > > > >
> > > > >
> > > >
> > > >
> > > >
> _______________________________________________
> > > > This is the Java Programming on and around the
> > > > iSeries / AS400 (JAVA400-L) mailing list
> > > > To post a message email:
> JAVA400-L@xxxxxxxxxxxx
> > > > To subscribe, unsubscribe, or change list
> > options,
> > > > visit:
> > > >
> >
> http://lists.midrange.com/mailman/listinfo/java400-l
> > > > or email: JAVA400-L-request@xxxxxxxxxxxx
> > > > Before posting, please take a moment to review
> > the
> > > > archives
> > > > at http://archive.midrange.com/java400-l.
> > > >
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > Yahoo! SiteBuilder - Free web site building
> tool.
> > Try it!
> > > http://webhosting.yahoo.com/ps/sb/
> > > _______________________________________________
> > > This is the Java Programming on and around the
> > iSeries / AS400 (JAVA400-L)
> > mailing list
> > > To post a message email: JAVA400-L@xxxxxxxxxxxx
> > > To subscribe, unsubscribe, or change list
> options,
> > > visit:
> >
> http://lists.midrange.com/mailman/listinfo/java400-l
> > > or email: JAVA400-L-request@xxxxxxxxxxxx
> > > Before posting, please take a moment to review
> the
> > archives
> > > at http://archive.midrange.com/java400-l.
> > >
> > >
> > 
> > 
> > _______________________________________________
> > This is the Java Programming on and around the
> > iSeries / AS400 (JAVA400-L) mailing list
> > To post a message email: JAVA400-L@xxxxxxxxxxxx
> > To subscribe, unsubscribe, or change list options,
> > visit:
> >
> http://lists.midrange.com/mailman/listinfo/java400-l
> > or email: JAVA400-L-request@xxxxxxxxxxxx
> > Before posting, please take a moment to review the
> > archives
> > at http://archive.midrange.com/java400-l.
> > 
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Finance: Get your refund fast by filing
> online.
> http://taxes.yahoo.com/filing.html
> _______________________________________________
> This is the Java Programming on and around the
> iSeries / AS400 (JAVA400-L)
> mailing list To post a message email:
> JAVA400-L@xxxxxxxxxxxx To subscribe,
> unsubscribe, or change list options,
> visit:
> http://lists.midrange.com/mailman/listinfo/java400-l
> or email: JAVA400-L-request@xxxxxxxxxxxx
> Before posting, please take a moment to review the
> archives
> at http://archive.midrange.com/java400-l.
> 
> This e-mail has been sent by a company of Bertram
> Group Ltd, whose registered office is The Nest,
> Rosary Road Norwich NR1 1TF. 
> This message, and any attachments, are intended
> solely for the addressee and may contain privileged
> or confidential information.  If you are not the
> intended recipient, any disclosure, copying,
> distribution or any action taken or omitted to be
> taken in reliance on it, is prohibited and may be
> unlawful.  If you believe that you have received
> this email in error, please contact the sender
> immediately. Opinions, conclusions and statements of
> intent in this e-mail are those of the sender and
> will not bind a Bertram Group Ltd company unless
> confirmed in writing by a director independently of
> this message. 
> Although we have taken steps to ensure that this
> email and any attachments are free from any virus,
> we advise that in keeping with good computing
> practice the recipient should ensure they are
> actually virus free.
> 
> _______________________________________________
> This is the Java Programming on and around the
> iSeries / AS400 (JAVA400-L) mailing list
> To post a message email: JAVA400-L@xxxxxxxxxxxx
> To subscribe, unsubscribe, or change list options,
> visit:
> http://lists.midrange.com/mailman/listinfo/java400-l
> or email: JAVA400-L-request@xxxxxxxxxxxx
> Before posting, please take a moment to review the
> archives
> at http://archive.midrange.com/java400-l.
> 


=====
A$HI$H

__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html
_______________________________________________
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) 
mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.