<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Nivek's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Wed, 23 Jul 2008 22:40:28 GMT</pubDate>
    <description>DZone Snippets: Nivek's Code Snippets</description>
    <item>
      <title>Which class file is loaded by the classloader ?</title>
      <link>http://snippets.dzone.com/posts/show/3719</link>
      <description>When using lots of third-party libraries, one problem might be that 2 of them package different versions of the same class, producing errors when method version conflicts happen.&lt;br /&gt;&lt;br /&gt;Here is a simple way to know the exact location used by the classloader to get your class :&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;URL myClassURL = MyMysteryClass.class.getProtectionDomain().getCodeSource().getLocation();&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 23 Mar 2007 11:38:37 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3719</guid>
      <author>nivek (Kevin Gaudin)</author>
    </item>
    <item>
      <title>StopWatch - Why is my app so slow ???</title>
      <link>http://snippets.dzone.com/posts/show/3474</link>
      <description>StopWatch is a small class allowing to manage multiple concurrent stopwatches to measure time elapsed between two calls. Nothing is done while time is rolling (no thread, no loop), it only stores and compares timestamps.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import java.util.Hashtable;&lt;br /&gt;&lt;br /&gt;public class StopWatch {&lt;br /&gt;    private static final Hashtable startTime = new Hashtable();&lt;br /&gt;    &lt;br /&gt;    public static void start(String id){&lt;br /&gt;        startTime.put(id,new Long(System.currentTimeMillis()));&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static long stop(String id){&lt;br /&gt;        return System.currentTimeMillis() - ((Long)startTime.remove(id)).longValue();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Example of use :&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public main(String[] args) {&lt;br /&gt;    // Start a global stopwatch&lt;br /&gt;    StopWatch.start("GLOBAL");&lt;br /&gt;&lt;br /&gt;    // evaluate time used by task 1&lt;br /&gt;    StopWatch.start("TASK1");&lt;br /&gt;    executeTask1();&lt;br /&gt;    System.out.println("Time elapsed for task 1 : " + StopWatch.stop("TASK1") + "ms";&lt;br /&gt;&lt;br /&gt;    // evaluate time used by task 2&lt;br /&gt;    StopWatch.start("TASK2");&lt;br /&gt;    executeTask2();&lt;br /&gt;    System.out.println("Time elapsed for task 2 : " + StopWatch.stop("TASK2") + "ms";&lt;br /&gt;&lt;br /&gt;    // Display time elapsed for full processing&lt;br /&gt;    System.out.println("Total processing time : " + StopWatch.stop("GLOBAL") + "ms";&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 07 Feb 2007 21:51:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3474</guid>
      <author>nivek (Kevin Gaudin)</author>
    </item>
  </channel>
</rss>
