Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
LockDebugUtil.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021 Gothel Software e.K.
4 * Copyright (c) 2011 Gothel Software e.K.
5 * Copyright (c) 2011 JogAmp Community.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27package jau.test.util.parallel.locks.impl;
28
29import java.io.PrintStream;
30import java.util.ArrayList;
31import java.util.Iterator;
32import java.util.List;
33
34import jau.test.util.parallel.locks.Lock;
35
36/**
37 * Functionality enabled if {@link Lock#DEBUG} is <code>true</code>.
38 */
39public class LockDebugUtil {
40 private static final ThreadLocal<ArrayList<Throwable>> tlsLockedStacks;
41 private static final List<Throwable> dummy;
42 static {
43 if(Lock.DEBUG) {
44 tlsLockedStacks = new ThreadLocal<ArrayList<Throwable>>();
45 dummy = null;
46 } else {
47 tlsLockedStacks = null;
48 dummy = new ArrayList<Throwable>(0);
49 }
50 }
51
52 public static List<Throwable> getRecursiveLockTrace() {
53 if(Lock.DEBUG) {
54 ArrayList<Throwable> ls = tlsLockedStacks.get();
55 if(null == ls) {
56 ls = new ArrayList<Throwable>();
57 tlsLockedStacks.set(ls);
58 }
59 return ls;
60 } else {
61 return dummy;
62 }
63 }
64
65 public static void dumpRecursiveLockTrace(final PrintStream out) {
66 if(Lock.DEBUG) {
67 final List<Throwable> ls = getRecursiveLockTrace();
68 if(null!=ls && ls.size()>0) {
69 int j=0;
70 out.println("TLSLockedStacks: locks "+ls.size());
71 for(final Iterator<Throwable> i=ls.iterator(); i.hasNext(); j++) {
72 out.print(j+": ");
73 i.next().printStackTrace(out);
74 }
75 }
76 }
77 }
78}
Functionality enabled if Lock#DEBUG is true.
static void dumpRecursiveLockTrace(final PrintStream out)
static List< Throwable > getRecursiveLockTrace()
Specifying a thread blocking lock implementation.
Definition: Lock.java:34
static final boolean DEBUG
Enable via the property jogamp.debug.Lock
Definition: Lock.java:37