<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hitesh Sarda &#187; .NET</title>
	<atom:link href="http://hitesh.in/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://hitesh.in</link>
	<description>Thoughts on life, technology, education and entrepreneurship</description>
	<lastBuildDate>Fri, 30 Dec 2011 06:00:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Dumping thread stack trace in Java &amp; .NET</title>
		<link>http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/</link>
		<comments>http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 06:26:35 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[@work]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=609</guid>
		<description><![CDATA[Multi-threaded Java practitioners know about the indispensible ways to taking thread dumps to see a snapshot of what&#8217;s happening in the JVM, and resolve &#8216;hang&#8217; issues. There are plethora of options, ranging from simple command line tools and utilities to &#8230; <a href="http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Multi-threaded Java practitioners know about the indispensible ways to taking thread dumps to see a snapshot of what&#8217;s happening in the JVM, and resolve &#8216;hang&#8217; issues. There are plethora of options, ranging from simple command line tools and utilities to nice GUI applications to writing some code in your application. A sampling of such options:</p>
<h3>Stack trace in Java</h3>
<h4>Command Line</h4>
<p>If the application is running as a console application, you can try one of these:</p>
<p><strong>Sending a signal to the Java Virtual Machine</strong></p>
<p>On UNIX platforms you can send a signal to a program by using the kill command. This is the quit signal, which is handled by the JVM. For example, on Solaris you can use the command <code>kill -QUIT process_id</code>, where process_id is the process number of your Java program.</p>
<p><span id="more-609"></span>Alternatively you can enter the key sequence <code>&lt;ctrl&gt;\</code> in the window where the Java program was started. Sending this signal instructs a signal handler in the JVM, to recursively print out all the information on the threads and monitors inside the JVM.</p>
<p>To generate a stack trace on Windows, enter the key sequence <code>&lt;ctrl&gt;&lt;break&gt;</code> in the window where the Java program is running, or click the Close button on the window.<br />
(Excerpt from <a href="http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/">http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/</a>)</p>
<p>If the application is not running in a console, you can use the <a href="http://download.oracle.com/javase/1.5.0/docs/tooldocs/share/jstack.html">jstack</a> tool that ships with J2EE since 1.5</p>
<pre><strong>jstack</strong> [ option ] pid
<strong>jstack</strong> [ option ] executable core
<strong>jstack</strong> [ option ] [server-id@]remote-hostname-or-IP</pre>
<h4>GUI Tools</h4>
<p>Since the JVM provides APIs to hook in and get the thread state and other information, there are several tools in the market that allows you to see the state of the running application including the thread stack trace. One such freely available option is <a href="http://download-llnw.oracle.com/javase/6/docs/technotes/guides/visualvm/index.html">VisualVM</a>. In fact it ships with JDK these days. Although VisualVM is pretty self explanatory, here are some instructions to get you started. <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/threads.html">http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/threads.html</a></p>
<p><img title="screenshot of thread dump (stack trace) in thread dump sub-tab" src="http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/images/thread-dump-screen.png" alt="screenshot of timeline in Threads tab" /></p>
<p>You could also use jConsole for similar purpose, but I prefer VisualVM. Check this for more information: <a href="http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html#DeadlockDetection">http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html#DeadlockDetection</a></p>
<p><img src="http://java.sun.com/developer/technicalArticles/J2SE/jconsole/FindDeadlock-IDs.jpg" alt="Figure 11: Find Deadlocked Threads" width="675" height="530" border="0" /></p>
<h4>Programmatically capturing the stack trace</h4>
<p>from within an appilcation, you can call : <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#getStackTrace()" target="_blank">Thread.getAllStackTraces()</a>. But if you want to do the same from a different application, <a href="http://download.oracle.com/javase/6/docs/api/java/lang/management/ThreadMXBean.html" target="_blank">ThreadMXBean</a> exposes the needed data, which can be retrieved by using the <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/lang/management/ManagementFactory.html" target="_blank">JMX interface</a>.</p>
<h3>Dumping thread Stack trace in .NET</h3>
<p>.NET does not seem to have the variety of options like Java. The only reasonable option I have seen so far is the <a href="http://www.codeplex.com/wikipage?ProjectName=MSE" target="_blank">Managed Stack Explorer</a>. This can be run from the command line as</p>
<pre>mse /s /p &lt;pid&gt;</pre>
<p>or as a GUI application:</p>
<p><a href="http://hitesh.in/wp-content/uploads/2010/DumpingthreadstacktraceinJava.NET_76CB/image.png"><img style="display: inline; border: 0px;" title="image" src="http://hitesh.in/wp-content/uploads/2010/DumpingthreadstacktraceinJava.NET_76CB/image_thumb.png" alt="image" width="586" height="454" border="0" /></a></p>
<p>Since it is an open source (MSPL) project, I took a peek into its source to check the API used. It depends on some sample code released by the CLR Team called <a href="http://www.microsoft.com/downloads/details.aspx?familyid=38449a42-6b7a-4e28-80ce-c55645ab1310&amp;displaylang=en" target="_blank">mdbg</a>. This in turn is a managed layer on the unmanaged <a href="http://msdn.microsoft.com/en-us/library/bb397953.aspx" target="_blank">CLR Debugging Services API</a>.</p>
<p>From what I see there seems to be no direct way to get a stack trace in .NET, apart from either using the debugger API, or rolling your own on top of the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.aspx" target="_blank">StackTrace</a> class. Check <a href="http://stackoverflow.com/questions/51768/print-stack-trace-information-from-c" target="_blank">this question on StackOverflow</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The great runtime shootout</title>
		<link>http://hitesh.in/2009/the-great-runtime-shootout/</link>
		<comments>http://hitesh.in/2009/the-great-runtime-shootout/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 21:32:58 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Boo]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JVM]]></category>
		<category><![CDATA[TOTW]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=196</guid>
		<description><![CDATA[It is becoming more and more obvious that there are just two runtimes left to execute code, the Java Virtual Machine (JVM) and the Common Language Infrastructure (CLI). So, I decided to see how they stack up. Looks like both &#8230; <a href="http://hitesh.in/2009/the-great-runtime-shootout/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It is becoming more and more obvious that there are just two runtimes left to execute code, the <em>Java Virtual Machine</em> (JVM) and the <em>Common Language Infrastructure</em> (CLI). So, I decided to see how they stack up. Looks like both environments have something for everyone.</p>
<p>Here is a list of programming languages available on these runtimes.</p>
<p><a href="http://hitesh.in/wp-content/uploads/2009/08/slide0001_image001_thumb.png"><img style="display: inline; border: 0px initial initial;" title="JVM vs. CLR" src="http://hitesh.in/wp-content/uploads/2009/08/slide0001_image001_thumb.png" border="0" alt="JVM vs CLI" width="650" height="518" /></a></p>
<ol>
<li>Can run on CLI using IKVM.NET</li>
<li>Can run on JVM using Mainsoft solution</li>
<li>Not yet usable</li>
<li>Can run on CLR, but is behind the JVM implementation</li>
</ol>
<p>The main reason for the research was to identify a new language I should pick-up. I looked at Python and Ruby, but both have some sore thumbs that I just can&#8217;t stand. I really liked Boo and Groovy; they are similar to C#/Java in syntax and incorporate the good things from Python. Although I like Boo&#8217;s syntax and approach more than Groovy, Groovy has a more mature implementation and ecosystem. I will try to use Groovy for some hobby project and get a feel to things.</p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2009/the-great-runtime-shootout/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

