Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!