You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/04/07 09:18:25 UTC

[GitHub] [skywalking-java] Cool-Coding commented on a diff in pull request #146: [Feature] Add JDK ThreadPoolExecutor plugin(#8743)

Cool-Coding commented on code in PR #146:
URL: https://github.com/apache/skywalking-java/pull/146#discussion_r844910046


##########
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java:
##########
@@ -234,4 +235,12 @@ static void configureLogger() {
                 LogManager.setLogResolver(new PatternLogResolver());
         }
     }
+
+    public static void pluginInitCompleted() {
+        IS_PLUGIN_INIT_COMPLETED = true;
+    }
+
+    public static boolean isPluginInitCompleted() {
+        return IS_PLUGIN_INIT_COMPLETED;
+    }

Review Comment:
   the `FileWriter` class in Skywalking agent uses `ThreadPoolExecutor`. If plugins are not loaded, FileWriter is created. Then `ThreadPoolExecutor won't be instructed`. so we must make sure that after plugins are loaded, FileWriter can be created.
   
   ```
       private FileWriter() {
           logBuffer = new ArrayBlockingQueue(1024);
           final ArrayList<String> outputLogs = new ArrayList<String>(200);
           Executors.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("LogFileWriter"))
                    .scheduleAtFixedRate(new RunnableWithExceptionProtection(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                logBuffer.drainTo(outputLogs);
                                for (String log : outputLogs) {
                                    writeToFile(log + Constants.LINE_SEPARATOR);
                                }
                                try {
                                    fileOutputStream.flush();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            } finally {
                                outputLogs.clear();
                            }
                        }
                    }, new RunnableWithExceptionProtection.CallbackWhenException() {
                        @Override
                        public void handle(Throwable t) {
                        }
                    }), 0, 1, TimeUnit.SECONDS);
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org