forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
core/src/main/scala/org/apache/spark/ThreadDumpCollector.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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.apache.spark | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.util.{ThreadUtils, Utils} | ||
|
||
|
||
/** | ||
* Creates a thread dump collector thread which will call the specified collectThreadDumps | ||
* function at intervals of intervalMs. | ||
* | ||
* @param collectThreadDumps the thread dump collector function to call. | ||
* @param name the thread name for the thread dump collector. | ||
* @param intervalMs the interval between stack trace collections. | ||
*/ | ||
private[spark] class ThreadDumpCollector( | ||
collectThreadDumps: () => Unit, | ||
name: String, | ||
intervalMs: Long) extends Logging { | ||
// Executor for the thread collector task | ||
private val threadDumpCollector = ThreadUtils.newDaemonSingleThreadScheduledExecutor(name) | ||
|
||
/** Schedules a task to collect the thread dumps */ | ||
def start(): Unit = { | ||
val threadDumpCollectorTask = new Runnable() { | ||
override def run(): Unit = Utils.logUncaughtExceptions(collectThreadDumps()) | ||
} | ||
threadDumpCollector.scheduleAtFixedRate(threadDumpCollectorTask, intervalMs, intervalMs, | ||
TimeUnit.MILLISECONDS) | ||
} | ||
|
||
def stop(): Unit = { | ||
threadDumpCollector.shutdown() | ||
threadDumpCollector.awaitTermination(10, TimeUnit.SECONDS) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters