Skip to content

Commit

Permalink
add gc operation output for DtTransferInfo in MTC #53
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Dec 11, 2015
1 parent ed73383 commit 5a53b1d
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public String toString() {
", leafSpanIdInfo=" + leafSpanIdInfo +
'}';
}

// Output GC operation
@Override
protected void finalize() throws Throwable {
System.out.printf("DEBUG: gc DtTransferInfo traceId %s in thread %s: %s\n",
traceId, Thread.currentThread().getName(), this);
super.finalize();
}
}

private static MtContextThreadLocal<DtTransferInfo> transferInfo = new MtContextThreadLocal<DtTransferInfo>();
Expand All @@ -78,6 +86,7 @@ public static void main(String[] args) throws Exception {
}

Thread.sleep(1000);
// help to check GC status
System.gc();
Thread.sleep(1000);
}
Expand Down Expand Up @@ -108,6 +117,9 @@ static void rpcInvokeIn() {
// DistributedTracer Framework Code
////////////////////////////////////////////////
System.out.printf("Finished Rpc call %s with span %s.\n", traceId, leafSpanIdInfo);

// release context in ThreadLocal, avoid to be hold by thread, GC friendly.
transferInfo.remove();
}

static void syncMethod() {
Expand Down

0 comments on commit 5a53b1d

Please sign in to comment.