连接超时问题

时间:2016-08-19 14:06:59

标签: java rest jersey mailgun

我们正在使用 Mailgun HTTP API 发送电子邮件和Jersey jars来连接到mailgun API

以下是我的代码段:

ClientConfig cc = new DefaultClientConfig();

cc.getClasses().add(MultiPartWriter.class);
Client client = Client.create(cc);

String pwd = "key-xxx"
String server = "xxx";
String email_from = "xxx";
String emailAddresses = "xxx";
String subject = "Mailgun Notification";
String message1 = "This is a TEST Message";

client.addFilter(new HTTPBasicAuthFilter("api",pwd));

WebResource webResource = client.resource("https://api.mailgun.net/v3/"+server+"/messages");
FormDataMultiPart form = new FormDataMultiPart();
form.field("from", email_from); 
form.field("to", emailAddresses);
form.field("subject", subject);
form.field("html",message1);
webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class,form)

当我们逐个向循环中的500个用户发送电子邮件时,它不会抛出任何异常并在23秒内发送电子邮件 但是如果我们为1000个用户重复相同的过程,那么在发送给第927个用户时它会抛出异常:

  

com.sun.jersey.api.client.ClientHandlerException:java.net.ConnectException:连接超时

0 个答案:

没有答案