{"action":"created","comment":{"url":"https://api.github.com/repos/netty/netty/pulls/comments/68333189","id":68333189,"diff_hunk":"@@ -309,41 +331,86 @@ protected boolean removeTask(Runnable task) {\n      * @return {@code true} if and only if at least one task was run\n      */\n     protected boolean runAllTasks() {\n+        assert inEventLoop();\n         boolean fetchedAll;\n+        boolean ranAtLeastOne = false;\n+\n         do {\n             fetchedAll = fetchFromScheduledTaskQueue();\n-            Runnable task = pollTask();\n-            if (task == null) {\n-                return false;\n+            if (runAllTasksFrom(taskQueue)) {\n+                ranAtLeastOne = true;\n             }\n+        } while (!fetchedAll); // keep on processing until we fetched all scheduled tasks.\n \n-            for (;;) {\n-                try {\n-                    task.run();\n-                } catch (Throwable t) {\n-                    logger.warn(\"A task raised an exception.\", t);\n-                }\n+        if (ranAtLeastOne) {\n+            lastExecutionTime = ScheduledFutureTask.nanoTime();\n+        }\n+        afterRunningAllTasks(false);\n+        return ranAtLeastOne;\n+    }\n \n-                task = pollTask();\n-                if (task == null) {\n-                    break;\n-                }\n+    /**\n+     * Runs all tasks from the passed {@code taskQueue}.\n+     *\n+     * @param taskQueue To poll and execute all tasks.\n+     *\n+     * @return {@code true} if atleast one task was executed.\n+     */\n+    protected boolean runAllTasksFrom(Queue<Runnable> taskQueue) {\n+        boolean ranAtLeastOne = false;\n+        for (;;) {\n+            Runnable task = pollTaskFrom(taskQueue);\n+            if (task == null) {\n+                break;\n             }\n-        } while (!fetchedAll); // keep on processing until we fetched all scheduled tasks.\n-\n-        lastExecutionTime = ScheduledFutureTask.nanoTime();\n-        return true;\n+            ranAtLeastOne = true;","path":"common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java","position":96,"original_position":96,"commit_id":"e9e7813a892fba7a03b1f4c53ffbf4cd2d74c134","original_commit_id":"e9e7813a892fba7a03b1f4c53ffbf4cd2d74c134","user":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"body":"consider unrolling this loop ... this variable is only meaningful on the first iteration.\r\n\r\n```java\r\n    protected boolean runAllTasksFrom(Queue<Runnable> taskQueue) {\r\n        Runnable task = pollTaskFrom(taskQueue);\r\n        if (task == null) {\r\n            return false;\r\n        }\r\n        safeExecute(task);\r\n        for (;;) {\r\n            task = pollTaskFrom(taskQueue);\r\n            if (task == null) {\r\n                return true;\r\n            }\r\n            safeExecute(task);\r\n        }\r\n    }\r\n\r\n    private static void safeExecute(Runnable task) {\r\n        try {\r\n            task.run();\r\n        } catch (Throwable t) {\r\n            logger.warn(\"A task raised an exception. Task: {}\", task, t);\r\n        }\r\n    }\r\n```","created_at":"2016-06-23T23:30:26Z","updated_at":"2016-06-23T23:30:26Z","html_url":"https://github.com/netty/netty/pull/5445#discussion_r68333189","pull_request_url":"https://api.github.com/repos/netty/netty/pulls/5445","_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/comments/68333189"},"html":{"href":"https://github.com/netty/netty/pull/5445#discussion_r68333189"},"pull_request":{"href":"https://api.github.com/repos/netty/netty/pulls/5445"}}},"pull_request":{"url":"https://api.github.com/repos/netty/netty/pulls/5445","id":74830553,"html_url":"https://github.com/netty/netty/pull/5445","diff_url":"https://github.com/netty/netty/pull/5445.diff","patch_url":"https://github.com/netty/netty/pull/5445.patch","issue_url":"https://api.github.com/repos/netty/netty/issues/5445","number":5445,"state":"open","locked":false,"title":"Auto flush","user":{"login":"normanmaurer","id":439362,"avatar_url":"https://avatars.githubusercontent.com/u/439362?v=3","gravatar_id":"","url":"https://api.github.com/users/normanmaurer","html_url":"https://github.com/normanmaurer","followers_url":"https://api.github.com/users/normanmaurer/followers","following_url":"https://api.github.com/users/normanmaurer/following{/other_user}","gists_url":"https://api.github.com/users/normanmaurer/gists{/gist_id}","starred_url":"https://api.github.com/users/normanmaurer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/normanmaurer/subscriptions","organizations_url":"https://api.github.com/users/normanmaurer/orgs","repos_url":"https://api.github.com/users/normanmaurer/repos","events_url":"https://api.github.com/users/normanmaurer/events{/privacy}","received_events_url":"https://api.github.com/users/normanmaurer/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-06-22T18:09:04Z","updated_at":"2016-06-23T23:30:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"72446873a647b997acbecaaf28dbb4c9f4969eee","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/netty/netty/pulls/5445/commits","review_comments_url":"https://api.github.com/repos/netty/netty/pulls/5445/comments","review_comment_url":"https://api.github.com/repos/netty/netty/pulls/comments{/number}","comments_url":"https://api.github.com/repos/netty/netty/issues/5445/comments","statuses_url":"https://api.github.com/repos/netty/netty/statuses/e9e7813a892fba7a03b1f4c53ffbf4cd2d74c134","head":{"label":"netty:auto_flush","ref":"auto_flush","sha":"e9e7813a892fba7a03b1f4c53ffbf4cd2d74c134","user":{"login":"netty","id":473791,"avatar_url":"https://avatars.githubusercontent.com/u/473791?v=3","gravatar_id":"","url":"https://api.github.com/users/netty","html_url":"https://github.com/netty","followers_url":"https://api.github.com/users/netty/followers","following_url":"https://api.github.com/users/netty/following{/other_user}","gists_url":"https://api.github.com/users/netty/gists{/gist_id}","starred_url":"https://api.github.com/users/netty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netty/subscriptions","organizations_url":"https://api.github.com/users/netty/orgs","repos_url":"https://api.github.com/users/netty/repos","events_url":"https://api.github.com/users/netty/events{/privacy}","received_events_url":"https://api.github.com/users/netty/received_events","type":"Organization","site_admin":false},"repo":{"id":1064563,"name":"netty","full_name":"netty/netty","owner":{"login":"netty","id":473791,"avatar_url":"https://avatars.githubusercontent.com/u/473791?v=3","gravatar_id":"","url":"https://api.github.com/users/netty","html_url":"https://github.com/netty","followers_url":"https://api.github.com/users/netty/followers","following_url":"https://api.github.com/users/netty/following{/other_user}","gists_url":"https://api.github.com/users/netty/gists{/gist_id}","starred_url":"https://api.github.com/users/netty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netty/subscriptions","organizations_url":"https://api.github.com/users/netty/orgs","repos_url":"https://api.github.com/users/netty/repos","events_url":"https://api.github.com/users/netty/events{/privacy}","received_events_url":"https://api.github.com/users/netty/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/netty/netty","description":"Netty project - an event-driven asynchronous network application framework","fork":false,"url":"https://api.github.com/repos/netty/netty","forks_url":"https://api.github.com/repos/netty/netty/forks","keys_url":"https://api.github.com/repos/netty/netty/keys{/key_id}","collaborators_url":"https://api.github.com/repos/netty/netty/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/netty/netty/teams","hooks_url":"https://api.github.com/repos/netty/netty/hooks","issue_events_url":"https://api.github.com/repos/netty/netty/issues/events{/number}","events_url":"https://api.github.com/repos/netty/netty/events","assignees_url":"https://api.github.com/repos/netty/netty/assignees{/user}","branches_url":"https://api.github.com/repos/netty/netty/branches{/branch}","tags_url":"https://api.github.com/repos/netty/netty/tags","blobs_url":"https://api.github.com/repos/netty/netty/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/netty/netty/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/netty/netty/git/refs{/sha}","trees_url":"https://api.github.com/repos/netty/netty/git/trees{/sha}","statuses_url":"https://api.github.com/repos/netty/netty/statuses/{sha}","languages_url":"https://api.github.com/repos/netty/netty/languages","stargazers_url":"https://api.github.com/repos/netty/netty/stargazers","contributors_url":"https://api.github.com/repos/netty/netty/contributors","subscribers_url":"https://api.github.com/repos/netty/netty/subscribers","subscription_url":"https://api.github.com/repos/netty/netty/subscription","commits_url":"https://api.github.com/repos/netty/netty/commits{/sha}","git_commits_url":"https://api.github.com/repos/netty/netty/git/commits{/sha}","comments_url":"https://api.github.com/repos/netty/netty/comments{/number}","issue_comment_url":"https://api.github.com/repos/netty/netty/issues/comments{/number}","contents_url":"https://api.github.com/repos/netty/netty/contents/{+path}","compare_url":"https://api.github.com/repos/netty/netty/compare/{base}...{head}","merges_url":"https://api.github.com/repos/netty/netty/merges","archive_url":"https://api.github.com/repos/netty/netty/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/netty/netty/downloads","issues_url":"https://api.github.com/repos/netty/netty/issues{/number}","pulls_url":"https://api.github.com/repos/netty/netty/pulls{/number}","milestones_url":"https://api.github.com/repos/netty/netty/milestones{/number}","notifications_url":"https://api.github.com/repos/netty/netty/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/netty/netty/labels{/name}","releases_url":"https://api.github.com/repos/netty/netty/releases{/id}","deployments_url":"https://api.github.com/repos/netty/netty/deployments","created_at":"2010-11-09T09:22:21Z","updated_at":"2016-06-23T18:32:07Z","pushed_at":"2016-06-23T22:39:12Z","git_url":"git://github.com/netty/netty.git","ssh_url":"git@github.com:netty/netty.git","clone_url":"https://github.com/netty/netty.git","svn_url":"https://github.com/netty/netty","homepage":"http://netty.io/","size":69029,"stargazers_count":7144,"watchers_count":7144,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3643,"mirror_url":null,"open_issues_count":325,"forks":3643,"open_issues":325,"watchers":7144,"default_branch":"4.1"}},"base":{"label":"netty:4.1","ref":"4.1","sha":"278c36af0ca9f0e97d6d321a88c413155483c509","user":{"login":"netty","id":473791,"avatar_url":"https://avatars.githubusercontent.com/u/473791?v=3","gravatar_id":"","url":"https://api.github.com/users/netty","html_url":"https://github.com/netty","followers_url":"https://api.github.com/users/netty/followers","following_url":"https://api.github.com/users/netty/following{/other_user}","gists_url":"https://api.github.com/users/netty/gists{/gist_id}","starred_url":"https://api.github.com/users/netty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netty/subscriptions","organizations_url":"https://api.github.com/users/netty/orgs","repos_url":"https://api.github.com/users/netty/repos","events_url":"https://api.github.com/users/netty/events{/privacy}","received_events_url":"https://api.github.com/users/netty/received_events","type":"Organization","site_admin":false},"repo":{"id":1064563,"name":"netty","full_name":"netty/netty","owner":{"login":"netty","id":473791,"avatar_url":"https://avatars.githubusercontent.com/u/473791?v=3","gravatar_id":"","url":"https://api.github.com/users/netty","html_url":"https://github.com/netty","followers_url":"https://api.github.com/users/netty/followers","following_url":"https://api.github.com/users/netty/following{/other_user}","gists_url":"https://api.github.com/users/netty/gists{/gist_id}","starred_url":"https://api.github.com/users/netty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netty/subscriptions","organizations_url":"https://api.github.com/users/netty/orgs","repos_url":"https://api.github.com/users/netty/repos","events_url":"https://api.github.com/users/netty/events{/privacy}","received_events_url":"https://api.github.com/users/netty/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/netty/netty","description":"Netty project - an event-driven asynchronous network application framework","fork":false,"url":"https://api.github.com/repos/netty/netty","forks_url":"https://api.github.com/repos/netty/netty/forks","keys_url":"https://api.github.com/repos/netty/netty/keys{/key_id}","collaborators_url":"https://api.github.com/repos/netty/netty/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/netty/netty/teams","hooks_url":"https://api.github.com/repos/netty/netty/hooks","issue_events_url":"https://api.github.com/repos/netty/netty/issues/events{/number}","events_url":"https://api.github.com/repos/netty/netty/events","assignees_url":"https://api.github.com/repos/netty/netty/assignees{/user}","branches_url":"https://api.github.com/repos/netty/netty/branches{/branch}","tags_url":"https://api.github.com/repos/netty/netty/tags","blobs_url":"https://api.github.com/repos/netty/netty/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/netty/netty/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/netty/netty/git/refs{/sha}","trees_url":"https://api.github.com/repos/netty/netty/git/trees{/sha}","statuses_url":"https://api.github.com/repos/netty/netty/statuses/{sha}","languages_url":"https://api.github.com/repos/netty/netty/languages","stargazers_url":"https://api.github.com/repos/netty/netty/stargazers","contributors_url":"https://api.github.com/repos/netty/netty/contributors","subscribers_url":"https://api.github.com/repos/netty/netty/subscribers","subscription_url":"https://api.github.com/repos/netty/netty/subscription","commits_url":"https://api.github.com/repos/netty/netty/commits{/sha}","git_commits_url":"https://api.github.com/repos/netty/netty/git/commits{/sha}","comments_url":"https://api.github.com/repos/netty/netty/comments{/number}","issue_comment_url":"https://api.github.com/repos/netty/netty/issues/comments{/number}","contents_url":"https://api.github.com/repos/netty/netty/contents/{+path}","compare_url":"https://api.github.com/repos/netty/netty/compare/{base}...{head}","merges_url":"https://api.github.com/repos/netty/netty/merges","archive_url":"https://api.github.com/repos/netty/netty/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/netty/netty/downloads","issues_url":"https://api.github.com/repos/netty/netty/issues{/number}","pulls_url":"https://api.github.com/repos/netty/netty/pulls{/number}","milestones_url":"https://api.github.com/repos/netty/netty/milestones{/number}","notifications_url":"https://api.github.com/repos/netty/netty/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/netty/netty/labels{/name}","releases_url":"https://api.github.com/repos/netty/netty/releases{/id}","deployments_url":"https://api.github.com/repos/netty/netty/deployments","created_at":"2010-11-09T09:22:21Z","updated_at":"2016-06-23T18:32:07Z","pushed_at":"2016-06-23T22:39:12Z","git_url":"git://github.com/netty/netty.git","ssh_url":"git@github.com:netty/netty.git","clone_url":"https://github.com/netty/netty.git","svn_url":"https://github.com/netty/netty","homepage":"http://netty.io/","size":69029,"stargazers_count":7144,"watchers_count":7144,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3643,"mirror_url":null,"open_issues_count":325,"forks":3643,"open_issues":325,"watchers":7144,"default_branch":"4.1"}},"_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/5445"},"html":{"href":"https://github.com/netty/netty/pull/5445"},"issue":{"href":"https://api.github.com/repos/netty/netty/issues/5445"},"comments":{"href":"https://api.github.com/repos/netty/netty/issues/5445/comments"},"review_comments":{"href":"https://api.github.com/repos/netty/netty/pulls/5445/comments"},"review_comment":{"href":"https://api.github.com/repos/netty/netty/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/netty/netty/pulls/5445/commits"},"statuses":{"href":"https://api.github.com/repos/netty/netty/statuses/e9e7813a892fba7a03b1f4c53ffbf4cd2d74c134"}}}}
{"actor":{"display_login":"Scottmitch"}}