Skip to content

README.md样例代码问题  #144

Description

@victorkevin2

示例代码

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....
	       }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions