Shreyas arya

Generation

generate functionThu, 09 Feb 2023

string = shreyas print string Number of retries = 3 if total duration of all attempts exceed 10 seconds then throw execption

public static void main(String[] args) throws Exception { final long startTime = System.currentTimeMillis(); int retries = 0; final int maxRetries = 3; final long timeout = 10000; while(true) { try { if (retries > maxRetries) { throw new Exception("Too many retries"); } String str = String.valueOf("shreyas"); System.out.println(str); break; } catch (Exception e) { retries++; final long elapsed = System.currentTimeMillis() - startTime; if (elapsed >= timeout) { throw e; } } } }

Questions about programming?Chat with your personal AI assistant