Add DEV.3.2/cours/Traces.java
This commit is contained in:
22
DEV.3.2/cours/Traces.java
Normal file
22
DEV.3.2/cours/Traces.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Traces {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// On récupère la map/dictionnaire qui contient les threads et leur traces
|
||||||
|
Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces();
|
||||||
|
|
||||||
|
//Parcours de chaque entrée de la Map (Clé: Thread, Valeur: Tableau de StackTraceElement)
|
||||||
|
for(Map.Entry<Thread, StackTraceElement[]> entry : traces.entrySet()) {
|
||||||
|
Thread thread = entry.getKey();
|
||||||
|
StackTraceElement[] stackElements = entry.getValue();
|
||||||
|
|
||||||
|
System.out.println(thread.getName()+" :");
|
||||||
|
|
||||||
|
for(StackTraceElement element : stackElements) {
|
||||||
|
System.out.println("\t"+element.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user