com.ibm.as400.access

Class ConnectionPool

  • java.lang.Object
    • com.ibm.as400.access.ConnectionPool
    • Constructor Summary

      Constructors 
      Constructor and Description
      ConnectionPool() 
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void addConnectionPoolListener(ConnectionPoolListener listener)
      Adds a ConnectionPoolListener.
      void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
      Adds a PropertyChangeListener.
      abstract void close()
      Closes the connection pool.
      protected void finalize()
      Closes the connection pool if not explicitly closed by the caller.
      long getCleanupInterval()
      Returns the time interval for how often the maintenance daemon is run.
      int getMaxConnections()
      Returns the maximum number of connections.
      long getMaxInactivity()
      Returns the maximum amount of inactive time before an available connection is closed.
      long getMaxLifetime()
      Returns the maximum life for an available connection.
      int getMaxUseCount()
      Returns the maximum number of times a connection can be used before it is replaced in the pool.
      long getMaxUseTime()
      Returns the maximum amount of time a connection can be in use before it is closed and returned to the pool.
      boolean isPretestConnections()
      Indicates whether connections are pretested before they are allocated to requesters.
      boolean isRunMaintenance()
      Indicates whether the maintenance thread is used to cleanup expired connections.
      boolean isThreadUsed()
      Indicates whether threads are used in communication with the host servers and for running maintenance.
      void removeConnectionPoolListener(ConnectionPoolListener listener)
      Removes a ConnectionPoolListener.
      void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
      Removes a PropertyChangeListener.
      void setCleanupInterval(long cleanupInterval)
      Sets the time interval for how often the maintenance daemon is run.
      void setMaxConnections(int maxConnections)
      Sets the maximum number of connections.
      void setMaxInactivity(long maxInactivity)
      Sets the maximum amount of inactive time before an available connection is closed.
      void setMaxLifetime(long maxLifetime)
      Sets the maximum life for an available connection.
      void setMaxUseCount(int maxUseCount)
      Sets the maximum number of times a connection can be used before it is replaced in the pool.
      void setMaxUseTime(long maxUseTime)
      Sets the maximum amount of time a connection can be in use before it is closed and returned to the pool.
      void setPretestConnections(boolean pretest)
      Sets whether connections are pretested before they are allocated to requesters.
      void setRunMaintenance(boolean cleanup)
      Sets whether the Toolbox does periodic maintenance on the connection pool to clean up expired connections.
      void setThreadUsed(boolean useThreads)
      Sets whether the IBM Toolbox for Java uses additional threads.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConnectionPool

        public ConnectionPool()
    • Method Detail

      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Closes the connection pool if not explicitly closed by the caller.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable - If an error occurs.
      • getCleanupInterval

        public long getCleanupInterval()
        Returns the time interval for how often the maintenance daemon is run. The default value is 300000 milliseconds (5 minutes).
        Returns:
        Number of milliseconds.
      • getMaxConnections

        public int getMaxConnections()
        Returns the maximum number of connections. The default value is -1 indicating no limit to the number of connections.
        Returns:
        Maximum number of connections.
      • getMaxInactivity

        public long getMaxInactivity()
        Returns the maximum amount of inactive time before an available connection is closed. The maintenance daemon closes the connection if the threshold is reached. The default value is 60 minutes. A value of -1 indicates that there is no limit.
        Returns:
        Number of milliseconds.
      • getMaxLifetime

        public long getMaxLifetime()
        Returns the maximum life for an available connection. The maintenance daemon closes the available connection if the threshold is reached. The default value is a 24 hour limit. A value of -1 indicates that there is no limit.
        Returns:
        Number of milliseconds.
      • getMaxUseCount

        public int getMaxUseCount()
        Returns the maximum number of times a connection can be used before it is replaced in the pool. The default value is -1. A value of -1 indicates that there is no limit.
        Returns:
        Maximum usage count.
      • getMaxUseTime

        public long getMaxUseTime()
        Returns the maximum amount of time a connection can be in use before it is closed and returned to the pool. The default value is -1 indicating that there is no limit.
        Returns:
        Number of milliseconds.
      • isPretestConnections

        public boolean isPretestConnections()
        Indicates whether connections are pretested before they are allocated to requesters. Pretesting verifies that the connection is still valid. By default, connections are not pretested.

        Note: The pretestConnections property is not fully effective until IBM i 7.1.

        Returns:
        true if connections are pretested before being allocated; false otherwise.
        See Also:
        AS400.isConnectionAlive()
      • isRunMaintenance

        public boolean isRunMaintenance()
        Indicates whether the maintenance thread is used to cleanup expired connections. The default is true.
        Returns:
        true if expired connection are cleaned up by the maintenance thread; false otherwise.
      • isThreadUsed

        public boolean isThreadUsed()
        Indicates whether threads are used in communication with the host servers and for running maintenance. This property affects AS400ConnectionPool and not AS400JDBCConnectionPool which is written to the JDBC specification. The default value is true.
        Returns:
        true if threads are used; false otherwise.
      • setCleanupInterval

        public void setCleanupInterval(long cleanupInterval)
        Sets the time interval for how often the maintenance daemon is run. The default value is 300000 milliseconds or 5 minutes.
        Parameters:
        cleanupInterval - The number of milliseconds.
      • setMaxConnections

        public void setMaxConnections(int maxConnections)
        Sets the maximum number of connections. The default value is -1 indicating no limit to the number of connections.
        Parameters:
        maxConnections - Maximum number of connections.
      • setMaxInactivity

        public void setMaxInactivity(long maxInactivity)
        Sets the maximum amount of inactive time before an available connection is closed. The maintenance daemon closes the connection if the threshold is reached. The default value is 60 minutes. A value of -1 indicates that there is no limit.
        Parameters:
        maxInactivity - Number of milliseconds.
      • setMaxLifetime

        public void setMaxLifetime(long maxLifetime)
        Sets the maximum life for an available connection. The maintenance daemon closes the available connection if the threshold is reached. The default value is a 24 hour limit. A value of -1 indicates that there is no limit.
        Parameters:
        maxLifetime - Number of milliseconds.
      • setMaxUseCount

        public void setMaxUseCount(int maxUseCount)
        Sets the maximum number of times a connection can be used before it is replaced in the pool. The default value is -1. A value of -1 indicates that there is no limit.
        Parameters:
        maxUseCount - Maximum usage count.
      • setMaxUseTime

        public void setMaxUseTime(long maxUseTime)
        Sets the maximum amount of time a connection can be in use before it is closed and returned to the pool. The default value is -1 indicating that there is no limit.
        Parameters:
        maxUseTime - Number of milliseconds.
      • setPretestConnections

        public void setPretestConnections(boolean pretest)
        Sets whether connections are pretested before they are allocated to requesters. Pretesting verifies that the connection is still valid. By default, connections are not pretested.

        Note: The pretestConnections property is not fully effective until IBM i 7.1.

        Parameters:
        pretest - If connections are pretested before being allocated.
        See Also:
        AS400.isConnectionAlive()
      • setRunMaintenance

        public void setRunMaintenance(boolean cleanup)
        Sets whether the Toolbox does periodic maintenance on the connection pool to clean up expired connections. If setThreadUsed is true, the Toolbox starts an extra thread to perform maintenance. If setThreadUsed is false, the Toolbox will perform maintenance on the user's thread when it uses the connection pool. This method and setThreadUsed can be set in interchangeable order. The default value is true.
        Parameters:
        cleanup - If expired connections are cleaned up by the maintenance daemon.
      • setThreadUsed

        public void setThreadUsed(boolean useThreads)
        Sets whether the IBM Toolbox for Java uses additional threads. The Toolbox creates additional threads for various purposes, including:
        • for communication with the host servers; and
        • for running pool maintenance.
        Letting the IBM Toolbox for Java use additional threads will be beneficial to performance, but turning threads off may be necessary if your application needs to be compliant with the Enterprise Java Beans specification. The threadUsed property cannot be changed once the pool is in use. This property affects AS400ConnectionPool and not AS400JDBCConnectionPool, which is written to the JDBC specification. This method and setRunMaintenance can be called in interchangeable order. The default value is true.
        Parameters:
        useThreads - true to use additional threads; false otherwise.