title: failed to create a child event loop/failed to open a new selector/Too many open files
body: <p>I am getting errors like "failed to create a child event loop/failed to open a new selector/Too many open files" when <strong>there are 30 or more concurrent requests</strong>...How to solve the above errors? Am I doing anything wrong? I am using Spring boot and Java cassandra driver. <strong>Below is the connection file</strong>: </p>
  
  <pre><code>public class Connection {
  
  public static Session getConnection() {
  
      final Cluster cluster = Cluster.builder().addContactPoint(ConnectionBean.getCASSANDRA_DB_IP())
              .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_ONE))
              .withCredentials(ConnectionBean.getCASSANDRA_USER(), ConnectionBean.getCASSANDRA_PASSWORD())
              .withPoolingOptions(poolingOptions)
              .build();
      final Session session = cluster.connect(ConnectionBean.getCASSANDRA_DB_NAME());
      return session;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Below is the ConnectionBean file which I used in Connection file:</strong></p>
  
  <pre><code>public  class ConnectionBean {
  
  public static   String CASSANDRA_DB_IP;
  public static String CASSANDRA_DB_NAME;
  public static  String CASSANDRA_USER;
  public static String CASSANDRA_PASSWORD;
  
  public ConnectionBean() {
  
  }
  public ConnectionBean(String CASSANDRA_DB_IP,String CASSANDRA_DB_NAME,String CASSANDRA_USER,String CASSANDRA_PASSWORD) {
  this.CASSANDRA_DB_IP=CASSANDRA_DB_IP;
  this.CASSANDRA_DB_NAME=CASSANDRA_DB_NAME;
  this.CASSANDRA_USER=CASSANDRA_USER;
  this.CASSANDRA_PASSWORD=CASSANDRA_PASSWORD;
  }
  
  public static String getCASSANDRA_DB_IP() {
      return CASSANDRA_DB_IP;
  }
  public static void setCASSANDRA_DB_IP(String cASSANDRA_DB_IP) {
      CASSANDRA_DB_IP = cASSANDRA_DB_IP;
  }
  public static String getCASSANDRA_DB_NAME() {
      return CASSANDRA_DB_NAME;
  }
  public static void setCASSANDRA_DB_NAME(String cASSANDRA_DB_NAME) {
      CASSANDRA_DB_NAME = cASSANDRA_DB_NAME;
  }
  public static String getCASSANDRA_USER() {
      return CASSANDRA_USER;
  }
  public static void setCASSANDRA_USER(String cASSANDRA_USER) {
      CASSANDRA_USER = cASSANDRA_USER;
  }
  public static String getCASSANDRA_PASSWORD() {
      return CASSANDRA_PASSWORD;
  }
  public static void setCASSANDRA_PASSWORD(String cASSANDRA_PASSWORD) {
      CASSANDRA_PASSWORD = cASSANDRA_PASSWORD;
  }   
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Below is the class from where ConnectionBean variables are initialized :</strong></p>
  
  <pre><code>public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  private static final String LOGIN_PROCESSING_URL = "/login";
  private static final String LOGIN_FAILURE_URL = "/login?error";
  private static final String LOGIN_URL = "/login";
  
  @Autowired
  private BCryptPasswordEncoder bCryptPasswordEncoder;
  
  @Autowired
  private DataSource dataSource;
  
  @Value("${spring.queries.users-query}")
  private String usersQuery;
  
  @Value("${spring.queries.roles-query}")
  private String rolesQuery;
  
  @Value("${CASSANDRA_DB_IP}")
  public String CASSANDRA_DB_IP;
  
  @Value("${CASSANDRA_DB_NAME}")
  public String CASSANDRA_DB_NAME;
  
  @Value("${CASSANDRA_USER}")
  public String CASSANDRA_USER;
  
  @Value("${CASSANDRA_PASSWORD}")
  public String CASSANDRA_PASSWORD;
  
  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      ConnectionBean cb = new ConnectionBean(CASSANDRA_DB_IP, CASSANDRA_DB_NAME, CASSANDRA_USER, CASSANDRA_PASSWORD);
  
      auth.jdbcAuthentication().usersByUsernameQuery(usersQuery).authoritiesByUsernameQuery(rolesQuery)
              .dataSource(dataSource).passwordEncoder(bCryptPasswordEncoder);
  }
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
      // Not using Spring CSRF here to be able to use plain HTML for the login page
  
      http.csrf().disable()
  
              // Register our CustomRequestCache, that saves unauthorized access attempts, so
              // the user is redirected after login.
              .requestCache().requestCache(new CustomRequestCache())
  
              // Restrict access to our application.
              .and().authorizeRequests()
  
              // Allow all flow internal requests.
              .requestMatchers(SecurityUtils::isFrameworkInternalRequest).permitAll()
  
              // Allow all requests by logged in users.
              .anyRequest().authenticated()
  
              // Configure the login page.
              .and().formLogin().loginPage(LOGIN_URL).permitAll().loginProcessingUrl(LOGIN_PROCESSING_URL)
              .failureUrl(LOGIN_FAILURE_URL)
  
              // Register the success handler that redirects users to the page they last tried
              // to access
              .successHandler(new SavedRequestAwareAuthenticationSuccessHandler())
  
              // Configure logout
              .and().logout().logoutSuccessUrl(LOGOUT_SUCCESS_URL);
  }
  
  /**
   * Allows access to static resources, bypassing Spring security.
   */
  @Override
  public void configure(WebSecurity web) throws Exception {
      web.ignoring().antMatchers(
              // Vaadin Flow static resources
              "/VAADIN/**",
  
              // the standard favicon URI
              "/favicon.ico",
  
              // web application manifest
              "/manifest.json", "/sw.js", "/offline-page.html",
  
              // icons and images
              "/icons/**", "/images/**",
  
              // (development mode) static resources
              "/frontend/**",
  
              // (development mode) webjars
              "/webjars/**",
  
              // (development mode) H2 debugging console
              "/h2-console/**",
  
              // (production mode) static resources
              "/frontend-es5/**", "/frontend-es6/**");
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>And finally, below is the class through which I am querying cassandra data:</strong></p>
  
  <pre><code>public class getData {
  Session session;
  
  public getData(){
      session = Connection.getConnection();
      getDataTable();
  }
  
  private void getDataTable() {
      try {
          String query = "SELECT * FROM tableName";
          ResultSet rs = session.execute(query);
          for (Row row : rs) {
              /*Do some stuff here using row*/
          }
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>