Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Retry logic for FTP when IOException occurs

 
Charles Ben
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone suggest the best practice for retry logic to be implemented
when a particular exception eg:IOException happens and then the code can retry for
n times with a time gap before throwing an exception.


public FTPClient getFtpClient() throws IOException,Exception
{
try
{
System.out.println("B4 login ");
FTPClient m_FtpClient = loginToRemoteServer();
System.out.println("After login to remote server");
return m_FtpClient;
}

catch(IOException excp)
{
System.out.println("IO Exception ");
// retry logic to be added here when IO Exception happens at loginToRemoteServer() method
throw excp;
}
catch(Exception excp)
{
System.out.println("Exception ");
throw excp;
}
}
 
Jeanne Boyarsky
author & internet detective
Posts: 40912
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Charles Ben wrote:Can someone suggest the best practice for retry logic to be implemented


You mean like a loop:
 
Charles Ben
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes something like this..

Your post have given idea to take it further ..

Thanks a lot Jeanne.
 
S Mürset
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exceptions shouldn't be returned but catched. This is my suggestion. I don't fully understand in which case you want to wait, this is just a guess. You can fix it according to your wishes.

 
Charles Ben
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

S Mürset wrote: I don't fully understand in which case you want to wait, this is just a guess.




Thanks Mürset for your suggestion.

Wait i mentioned was to take care if the network is having some issues at that point.
Waiting and then trying for the connection after couple of minutes might sometime help.



reply
    Bookmark Topic Watch Topic
  • New Topic