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

BeatProcessor's run method can be never executed #25

Closed
wei7202839 opened this issue Aug 2, 2018 · 2 comments
Closed

BeatProcessor's run method can be never executed #25

wei7202839 opened this issue Aug 2, 2018 · 2 comments
Assignees

Comments

@wei7202839
Copy link

wei7202839 commented Aug 2, 2018

executeService是个singleThreadExecutor,BeatProcessor内部while (true)自旋
BeatTask的run方法是永远没有机会执行的,这个是故意的呢还是设计错误?

class BeatProcessor implements Runnable {

        @Override
        public void run() {
            while (true) {
                try {
                    for (Map.Entry<String, BeatInfo> entry : dom2Beat.entrySet()) {
                        BeatInfo beatInfo = entry.getValue();
                        executorService.schedule(new BeatTask(beatInfo), 0, TimeUnit.MILLISECONDS);
                        LogUtils.LOG.info("BEAT", "send beat to server: ", beatInfo.toString());
                    }

                    TimeUnit.MILLISECONDS.sleep(clientBeatInterval);
                } catch (Exception e) {
                    LogUtils.LOG.error("CLIENT-BEAT", "Exception while scheduling beat.", e);
                }
            }
        }
    }

    class BeatTask implements Runnable {
        BeatInfo beatInfo;

        public BeatTask(BeatInfo beatInfo) {
            this.beatInfo = beatInfo;
        }

        @Override
        public void run() {
            Map<String, String> params = new HashMap<String, String>(2);
            params.put("beat", JSON.toJSONString(beatInfo));
            params.put("dom", beatInfo.getDom());

            try {
                String result = serverProxy.callAllServers(UtilAndComs.NACOS_URL_BASE + "/api/clientBeat", params);
                JSONObject jsonObject = JSON.parseObject(result);

                if (jsonObject != null) {
                    clientBeatInterval = jsonObject.getLong("clientBeatInterval");

                }
            } catch (Exception e) {
                LogUtils.LOG.error("CLIENT-BEAT", "failed to send beat: " + JSON.toJSONString(beatInfo), e);
            }
        }
    }
@nkorange
Copy link
Collaborator

nkorange commented Aug 2, 2018

@wei7202839 It is a bug as you said. Are you interested in creating a PR to fix it?

@nkorange nkorange added the bug label Aug 3, 2018
@nkorange nkorange self-assigned this Aug 3, 2018
@nkorange
Copy link
Collaborator

nkorange commented Aug 3, 2018

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

2 participants