Reputation: 787
I need to introduce wait in application based on the size of an array.
So say if the size of the array is 100 then the wait time will be 5000
then for each next batch of 1000 the delay time will be incremented by 1 second each . What will be the best possible way to do this ?
Sample code
int waitTime = 5000;
if(array.length < 100)
{
waitTime= 5000;
}
if(array.length > 100 && array.length <=1000)
{
waitTime = waitTime+ 1000;
}
Upvotes: 0
Views: 87
Reputation: 54692
I find no problem with your code. But if you can create a relation between array size and sleep time then you can simply write in one line .. something like following
Thread.sleep(array.length < 100 ? 5000 : 6000 + 1000 * (array.length / 1000));
Upvotes: 1