Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
making a function not to work for a few some seconds in java

I have a login function.I want my function not work for example 10 seconds if the user call it for more than 5 time.what should i do for that?I will be glad if some one answer my question.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You need to record failed login attempts for a user (e.g. in database) and once it reaches the threshold, you need to return error response from login method for configurable amount of time from the last failed login attempt, e.g.:

  • When a login fails, log it into database (along with timestamp)
  • During login attempt, get failed attempt count and check whether it has reached the configured threshold
  • If it is over the threshold, check the timestamp for last login and block the call if current date is let's say within x minutes from that timestamp
  • On successful login, clear all the failed attempts
over 4 years ago · Santiago Trujillo Relatório

0

function not work for example 10 seconds

You need to be specific on what exactly you mean by function not to work. But if you simply wanted to block the method call for x seconds, follow the below approach:

You need to create a counter to count the number of attempts and then if(counter>5) then use Thread.sleep(10000) to make the request to hold (sleep) for 10 seconds. Ideally, the counter value should be persisted to a database (or any other storage) and read it again to validate the number of attempts.

But, I strongly suggest you follow @Darshan's answer which makes more sense.

over 4 years ago · Santiago Trujillo Relatório

0

First you need to identify the user .

This can be done on the basis of IP .

Have a ConcurrentHashMap

   ConcurrentHashMap<String,Long>IpAddressValidationMap  // String is the Ip address and Long is the timeInMilleseconds

You make a filter and put a check

     public void prefilterFunction(RequestObject object)
      {
          String ip=object.getIP(); // just an example not the standard call for getting Ip addr
           Long time=IpAddressValidationMap.get(ip);
           if(time!=null)
           { 
             if(time<THRESHOLD_TIME)
               {
                 return ;  
                 }     
                 else
                {
                 // We allow the user to proceed
                 }
            }
       }

      public void validateLogin(RequestObject object)
      {
       // if the login fails 
         IpAddressValidationMap.put(ipAddr,System.currentTimeinMIllis());   
       }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda