This is an automated email from the ASF dual-hosted git repository.

jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans-html4j.git

commit 7b3a10c627b37bb684e8dcbc3e7338cd6c36fa46
Author: Jaroslav Tulach <jaroslav.tul...@apidesign.org>
AuthorDate: Sun Jun 27 17:29:28 2021 +0200

    Dump stack after each minute of starvation
---
 .../html/presenters/browser/DumpStack.java         | 50 ++++++++++++++++++++++
 .../html/presenters/browser/ServerFactories.java   |  4 ++
 .../html/presenters/spi/test/DumpStack.java        | 50 ++++++++++++++++++++++
 .../html/presenters/spi/test/GenericTest.java      |  4 ++
 4 files changed, 108 insertions(+)

diff --git 
a/browser/src/test/java/org/netbeans/html/presenters/browser/DumpStack.java 
b/browser/src/test/java/org/netbeans/html/presenters/browser/DumpStack.java
new file mode 100644
index 0000000..d908dbc
--- /dev/null
+++ b/browser/src/test/java/org/netbeans/html/presenters/browser/DumpStack.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.html.presenters.browser;
+
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+
+final class DumpStack extends TimerTask {
+
+    private static final Timer TIMER = new Timer("Dump Stack Watchdog");
+    private final long created = System.currentTimeMillis();
+
+    @Override
+    public void run() {
+        StringBuilder sb = new StringBuilder();
+        long after = (System.currentTimeMillis() - created) / 1000;
+        sb.append("Thread dump after ").append(after).append(" s from 
start:\n");
+        for (Map.Entry<Thread, StackTraceElement[]> info : 
Thread.getAllStackTraces().entrySet()) {
+            sb.append(info.getKey().getName()).append("\n");
+            for (StackTraceElement e : info.getValue()) {
+                sb.append("    ").append(e.getClassName()).append(".").
+                        
append(e.getMethodName()).append("(").append(e.getFileName()).
+                        append(":").append(e.getLineNumber()).append(")\n");
+            }
+        }
+        System.err.println(sb.toString());
+    }
+
+    public static void initialize() {
+        final int minute = 60000;
+        TIMER.schedule(new DumpStack(), minute, 2 * minute);
+    }
+}
diff --git 
a/browser/src/test/java/org/netbeans/html/presenters/browser/ServerFactories.java
 
b/browser/src/test/java/org/netbeans/html/presenters/browser/ServerFactories.java
index c9233cd..a9997ba 100644
--- 
a/browser/src/test/java/org/netbeans/html/presenters/browser/ServerFactories.java
+++ 
b/browser/src/test/java/org/netbeans/html/presenters/browser/ServerFactories.java
@@ -35,6 +35,10 @@ public final class ServerFactories {
     private ServerFactories() {
     }
 
+    static {
+        DumpStack.initialize();
+    }
+
     @DataProvider(name = "serverFactories")
     public static Object[][] serverFactories() {
         Supplier<HttpServer<?,?,?,?>> grizzly = GrizzlyServer::new;
diff --git 
a/generic/src/test/java/org/netbeans/html/presenters/spi/test/DumpStack.java 
b/generic/src/test/java/org/netbeans/html/presenters/spi/test/DumpStack.java
new file mode 100644
index 0000000..3f31f2b
--- /dev/null
+++ b/generic/src/test/java/org/netbeans/html/presenters/spi/test/DumpStack.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.html.presenters.spi.test;
+
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+
+final class DumpStack extends TimerTask {
+
+    private static final Timer TIMER = new Timer("Dump Stack Watchdog");
+    private final long created = System.currentTimeMillis();
+
+    @Override
+    public void run() {
+        StringBuilder sb = new StringBuilder();
+        long after = (System.currentTimeMillis() - created) / 1000;
+        sb.append("Thread dump after ").append(after).append(" s from 
start:\n");
+        for (Map.Entry<Thread, StackTraceElement[]> info : 
Thread.getAllStackTraces().entrySet()) {
+            sb.append(info.getKey().getName()).append("\n");
+            for (StackTraceElement e : info.getValue()) {
+                sb.append("    ").append(e.getClassName()).append(".").
+                        
append(e.getMethodName()).append("(").append(e.getFileName()).
+                        append(":").append(e.getLineNumber()).append(")\n");
+            }
+        }
+        System.err.println(sb.toString());
+    }
+
+    public static void initialize() {
+        final int minute = 60000;
+        TIMER.schedule(new DumpStack(), minute, 2 * minute);
+    }
+}
diff --git 
a/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTest.java 
b/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTest.java
index 668d127..f9aae5b 100644
--- 
a/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTest.java
+++ 
b/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTest.java
@@ -34,6 +34,10 @@ public class GenericTest {
     public GenericTest() {
     }
 
+    static {
+        DumpStack.initialize();
+    }
+
     @Factory public static Object[] compatibilityTests() throws Exception {
         return createTests(new Testing());
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to