Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README.md样例代码问题 #144

Open
victorkevin2 opened this issue Sep 17, 2019 · 0 comments
Open

README.md样例代码问题 #144

victorkevin2 opened this issue Sep 17, 2019 · 0 comments

Comments

@victorkevin2
Copy link

示例代码

try {
    PushResult result = jpushClient.sendPush(payload);
    LOG.info("Got result - " + result);
    Thread.sleep(5000);
    // 请求结束后,调用 NettyHttpClient 中的 close 方法,否则进程不会退出。
    jpushClient.close();
} catch(InterruptedException e) {
    e.printStackTrace();
}

正确写法

jpushClient.close()应该放在finally方法体内或者实现AutoCloseable接口,这种示例代码严重误导人,正确写法:

JPushClient jpushClient =null;
try {
	    jpushClient = new JPushClient(MASTER_SECRET, APP_KEY);
	    PushPayload payload = PushPayload.alertAll(alert);
	    PushResult result = jpushClient.sendPush(payload);
	    this.output("Get result :" + result);
	    Thread.sleep(5000);
	} catch (Exception e) {
			Log....
	} finally {
	     try {
		    jpushClient.close();
	       } catch (Exception e) {
		     Log....
	       }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant