【发布时间】:2023-03-10 01:58:02
【问题描述】:
我已经搜索了一段时间,但我没有找到解决这个问题的具体独特解决方案,有些使用函数方法,如 .setTimeout(...) 左右,但我只想将超时设置为 public我项目中的方法。 为什么?因为在我向您展示的代码中,有时我在发布 wordpress 帖子的网站上没有答案,它会杀死所有预定的发布处理程序。
public void blogPublish(String articleTitle, String articleText, Date pubDate, String sourceDomain, String sourceAuthor, String blogCategory) throws XmlRpcFault{
String fullArticleContent = articleText;
XmlRpcArray categoryArray = new XmlRpcArray();
categoryArray.add(blogCategory);
this.post = new Page();
this.post.setTitle(articleTitle);
this.post.setDescription(fullArticleContent);
this.post.setDateCreated(pubDate);
this.post.setCategories(categoryArray);
String newPostIds = this.WP.newPost(post, true);
int newPostId = Integer.valueOf(newPostIds).intValue();
Page postNow = WP.getPost(newPostId);
System.out.println("Article Posted. Title=> "+ articleTitle);
}
如何使整个 blogPublish 函数超时?如果 5 秒后我仍然没有从我的网站上收到已完成发布的回复,我需要跳过它,因为它太慢或在那一刻无法访问。
【问题讨论】:
标签: java function methods timeout settimeout