Having hikari connection pool to retrive data from DB2 DB, during high load time we see the server is full when the hikari cp is reconnecting its not going to the new DB2 server in the load balancer and it going to the same DB2 server only, so the connection is not able to make as the load is already high on that DB2 server. And we see the other server loads are free but its not making.
Any one please share some input on this ?
Tried with a mock project to get the server name for every 5 sec retry establishing connection
@SpringBootApplication
@EnableScheduling
public class Mock {
static Connection connection;
static PreparedStatement statement;
static DataSource dataSource;
public static void main(String[] args) {
System.out.println("Hello world!");
SpringApplication.run(Main.class, args);
}
@PostConstruct
public static void data()
{
try{
dataSource=DataSourceBuilder.create()
.driverClassName("com.ibm.db2.jcc.DB2Driver")
.url("jdbc:db2://sfsdfsfsdfdsfdfdsfdsfsf;")
//.type(.class)
.build();
}catch(Exception e)
{
System.out.println("Errorinsql");
}
}
@Scheduled(cron="*/5 * * * * *")
public static void init() throws SQLException {
System.out.println("Helloworld!ConnectionStarted:");
//dataSource= DataSourceBuilder.create()
// .driverClassName("com.ibm.db2.jcc.DB2Driver")
// .url("jdbc:db2://sfsdfsfsdfdsfdfdsfdsfsf")
// .build();
connection=dataSource.getConnection();
statement=connection.prepareStatement("SELECT CURRENT MEMBER AS DATA FROM SYSIBM.SYSDUMMY1 WITH UR;");
ResultSet set=statement.executeQuery();
String name=null;
while(set.next()){
name=set.getString("Data");
}
System.out.println("Helloworld!ConnectionName:"+name);
statement.close();
connection.close();
System.out.println(connection.isClosed());
System.out.println("Helloworld!ConnectionClosed");
}
}
when I tried, if dataSource is reassigned on the init() method then its going to new server. if not reassigned and it will be assingned in the post construct method in data() method then its going to same server again and again even though I close the connection in the init() method.
so I want to know why the connection close is not woking as expected and
how can I reinitialize with new server on the connection hikari retry mechanism
And in my project we are hitting the db using the JdbcTemplate
@Bean(name = "db2DataSource")
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource db2DataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "db2Template")
@Primary
public JdbcTemplate jdbcTemplate(
@Qualifier("db2DataSource") DataSource db2DataSource) {
return new JdbcTemplate(db2DataSource);
}
and having JdbcTemplate to get the data .
How this bean is re established during the retry with new server connection
Thanks in advance