<?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>{Complexity} &#187; Java</title>
	<atom:link href="http://technote.wsjoung.com/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://technote.wsjoung.com</link>
	<description>simple note</description>
	<lastBuildDate>Fri, 06 Aug 2010 19:03:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Spring MVC + Tiles</title>
		<link>http://technote.wsjoung.com/2009/12/13/spring-mvc-tiles/</link>
		<comments>http://technote.wsjoung.com/2009/12/13/spring-mvc-tiles/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 02:14:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tiles]]></category>

		<guid isPermaLink="false">http://technote.wsjoung.com/?p=126</guid>
		<description><![CDATA[1. create web.xml &#60;?xml version="1.0" encoding="UTF-8"?&#62; &#60;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&#62; &#60;servlet&#62; &#60;servlet-name&#62;action&#60;/servlet-name&#62; &#60;servlet-class&#62;org.springframework.web.servlet.DispatcherServlet&#60;/servlet-class&#62; &#60;load-on-startup&#62;1&#60;/load-on-startup&#62; &#60;/servlet&#62; &#60;servlet-mapping&#62; &#60;servlet-name&#62;action&#60;/servlet-name&#62; &#60;url-pattern&#62;*.do&#60;/url-pattern&#62; &#60;/servlet-mapping&#62; &#60;/web-app&#62; 2. create action-servlet.xml &#60;?xml version="1.0" encoding="UTF-8"?&#62; &#60;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&#62; &#60;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&#62; &#60;property name="basename" value="message" /&#62; &#60;/bean&#62; &#60;bean id="testController" class="com.bluewiseinc.erp.common.web.TestController"&#62; &#60;property name="methodNameResolver" ref="methodNameResolver" /&#62; &#60;/bean&#62; &#60;bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"&#62; &#60;property [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1. create web.xml</strong><br />
<code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;<br />
  &lt;servlet&gt;<br />
  	&lt;servlet-name&gt;action&lt;/servlet-name&gt;<br />
	  &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;<br />
	  &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;<br />
  &lt;/servlet&gt;<br />
  &lt;servlet-mapping&gt;<br />
    &lt;servlet-name&gt;action&lt;/servlet-name&gt;<br />
    &lt;url-pattern&gt;*.do&lt;/url-pattern&gt;<br />
  &lt;/servlet-mapping&gt;<br />
&lt;/web-app&gt;</code></p>
<p><strong>2. create action-servlet.xml</strong><br />
<code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;</p>
<p>  &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&gt;<br />
    &lt;property name="basename" value="message" /&gt;<br />
  &lt;/bean&gt;  </p>
<p>  &lt;bean id="testController" class="com.bluewiseinc.erp.common.web.TestController"&gt;<br />
	&lt;property name="methodNameResolver" ref="methodNameResolver" /&gt;<br />
  &lt;/bean&gt;  </p>
<p>  &lt;bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"&gt;<br />
    &lt;property name="paramName"&gt;<br />
      &lt;value&gt;med&lt;/value&gt;<br />
    &lt;/property&gt;<br />
    &lt;property name="defaultMethodName"&gt;<br />
      &lt;value&gt;userMain&lt;/value&gt;<br />
    &lt;/property&gt;<br />
  &lt;/bean&gt;</p>
<p>  &lt;!--<br />
  &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;<br />
	&lt;property name="viewClass"&gt;<br />
	  &lt;value&gt;org.springframework.web.servlet.view.JstlView&lt;/value&gt;<br />
	&lt;/property&gt;<br />
	&lt;property name="cache" value="false" /&gt;<br />
	&lt;property name="prefix" value="/WEB-INF/view/" /&gt;<br />
	&lt;property name="suffix" value=".jsp" /&gt;<br />
  &lt;/bean&gt;<br />
  --&gt;<br />
  &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;<br />
    &lt;property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/&gt;<br />
  &lt;/bean&gt;</p>
<p>  &lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;<br />
	&lt;property name="mappings"&gt;<br />
	  &lt;bean class="org.springframework.beans.factory.config.PropertiesFactoryBean"&gt;<br />
	    &lt;property name="location"&gt;<br />
	      &lt;value&gt;/WEB-INF/UrlMap.properties&lt;/value&gt;<br />
	    &lt;/property&gt;<br />
	  &lt;/bean&gt;<br />
    &lt;/property&gt;<br />
  &lt;/bean&gt;</p>
<p>  &lt;bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"&gt;<br />
    &lt;property name="definitions"&gt;<br />
      &lt;list&gt;<br />
        &lt;value&gt;/WEB-INF/tiles-def.xml&lt;/value&gt;<br />
      &lt;/list&gt;<br />
    &lt;/property&gt;<br />
  &lt;/bean&gt;</p>
<p>  &lt;bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;<br />
    &lt;property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/&gt;<br />
  &lt;/bean&gt;<br />
&lt;/beans&gt;</code></p>
<p><strong>3. create TestController</strong><br />
<code>package com.bluewiseinc.erp.common.web;<br />
import javax.servlet.http.HttpServletRequest;<br />
import javax.servlet.http.HttpServletResponse;<br />
import org.springframework.web.servlet.ModelAndView;<br />
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;</p>
<p>public class TestController extends MultiActionController {<br />
	public ModelAndView testMain(HttpServletRequest request, HttpServletResponse response) throws Exception {<br />
		return new ModelAndView("test/test_main", "testMain", null);<br />
	}<br />
}</code></p>
<p><strong>4. UrlMap.properties</strong><br />
<code>## test module mapping<br />
/test/index.do=testController</code></p>
<p><strong>5. tiles-def.xml</strong><br />
<code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;<br />
&lt;!DOCTYPE tiles-definitions PUBLIC<br />
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"<br />
       "http://tiles.apache.org/dtds/tiles-config_2_0.dtd"&gt;</p>
<p>&lt;tiles-definitions&gt;<br />
  &lt;definition name="defaultTemplate" template="/WEB-INF/view/tiles/default.jsp"&gt;<br />
    &lt;put-attribute name="header" value="/WEB-INF/view/tiles/def_header.jsp" /&gt;<br />
    &lt;put-attribute name="menu" value="/WEB-INF/view/tiles/def_menu.jsp" /&gt;<br />
    &lt;put-attribute name="footer" value="/WEB-INF/view/tiles/def_footer.jsp" /&gt;<br />
  &lt;/definition&gt;<br />
  &lt;definition name="test_main" extends="defaultTemplate"&gt;<br />
    &lt;put-attribute name="content"   value="/WEB-INF/view/test/test_main.jsp"/&gt;<br />
  &lt;/definition&gt;<br />
&lt;/tiles-definitions&gt;</code></p>
<p><strong>6. message.properties</strong><br />
<code># Page titles<br />
index.title=Test Spring MVC + Tiles</code></p>
<p><strong>7. default.jsp</strong><br />
<code>&lt;%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %&gt;<br />
&lt;%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %&gt;<br />
&lt;%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %&gt;<br />
&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"<br />
    pageEncoding="ISO-8859-1"%&gt;<br />
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;<br />
&lt;title&gt;&lt;fmt:message key="index.title"/&gt;&lt;/title&gt;<br />
&lt;link rel=stylesheet href="${pageContext.request.contextPath}/css/global.css" type="text/css"&gt;<br />
&lt;script type="text/javascript" src="${pageContext.request.contextPath}/scripts/global.js"&gt;&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div id="header"&gt;<br />
    &lt;div id="headerTitle"&gt;&lt;tiles:insertAttribute name="header" /&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;div id="menu"&gt;<br />
    &lt;tiles:insertAttribute name="menu" /&gt;<br />
&lt;/div&gt;<br />
&lt;div id="content"&gt;<br />
    &lt;tiles:insertAttribute name="content" /&gt;<br />
&lt;/div&gt;<br />
&lt;div id="footer"&gt;<br />
    &lt;tiles:insertAttribute name="footer" /&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2009/12/13/spring-mvc-tiles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SwingWorker not on Java 6.0</title>
		<link>http://technote.wsjoung.com/2008/04/24/swingworker-not-on-java-60/</link>
		<comments>http://technote.wsjoung.com/2008/04/24/swingworker-not-on-java-60/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 14:15:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SwingWorker]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/?p=84</guid>
		<description><![CDATA[SwingWorker is useful when a time-consuming task has to be performed following a user-interaction event (for example, parsing a huge XML File, on pressing a Button). The most straightforward way to do it is : [sourcecode language='java'] private Document doc; &#8230; JButton button = new JButton(&#8220;Open XML&#8221;); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { [...]]]></description>
			<content:encoded><![CDATA[<p>SwingWorker is useful when a time-consuming task has to be performed following a user-interaction event (for example, parsing a huge XML File, on pressing a Button). The most straightforward way to do it is :</p>
<p>[sourcecode language='java']<br />
 private Document doc;<br />
 &#8230;<br />
 JButton button = new JButton(&#8220;Open XML&#8221;);<br />
 button.addActionListener(new ActionListener() {<br />
    public void actionPerformed(ActionEvent e) {<br />
       doc = loadXML();<br />
    }<br />
 });<br />
[/sourcecode]</p>
<p>This will work, but unfortunately, the loadXML() method will be called in the same thread as the main Swing thread, so if the method needs time to perform, the GUI will freeze during this time.</p>
<p>[sourcecode language='java']<br />
package com.wsjoung.demo;<br />
import javax.swing.SwingUtilities;</p>
<p>public abstract class SwingWorker {<br />
    // see getValue(), setValue()<br />
    private Object value;<br />
    private Thread thread;</p>
<p>    private static class ThreadVar {<br />
        private Thread thread;<br />
        ThreadVar(Thread t) { thread = t; }<br />
        synchronized Thread get() { return thread; }<br />
        synchronized void clear() { thread = null; }<br />
    }</p>
<p>    private ThreadVar threadVar;</p>
<p>    protected synchronized Object getValue() {<br />
        return value;<br />
    }</p>
<p>    private synchronized void setValue(Object x) {<br />
        value = x;<br />
    }</p>
<p>    public abstract Object construct();</p>
<p>    public void finished() {<br />
    }</p>
<p>    public void interrupt() {<br />
        Thread t = threadVar.get();<br />
        if (t != null) {<br />
            t.interrupt();<br />
        }<br />
        threadVar.clear();<br />
    }</p>
<p>    public Object get() {<br />
        while (true) {<br />
            Thread t = threadVar.get();<br />
            if (t == null) {<br />
                return getValue();<br />
            }<br />
            try {<br />
                t.join();<br />
            }<br />
            catch (InterruptedException e) {<br />
                // propagate<br />
                Thread.currentThread().interrupt();<br />
                return null;<br />
            }<br />
        }<br />
    }</p>
<p>    public SwingWorker() {<br />
        final Runnable doFinished = new Runnable() {<br />
           public void run() { finished(); }<br />
        };</p>
<p>        Runnable doConstruct = new Runnable() {<br />
            public void run() {<br />
                try {<br />
                    setValue(construct());<br />
                }<br />
                finally {<br />
                    threadVar.clear();<br />
                }</p>
<p>              SwingUtilities.invokeLater(doFinished);<br />
            }<br />
        };</p>
<p>        Thread t = new Thread(doConstruct);<br />
        threadVar = new ThreadVar(t);<br />
        t.start();<br />
    }<br />
}<br />
[/sourcecode]</p>
<p><a href="http://java.sun.com/products/jfc/tsc/articles/threads/src/SwingWorker.java">SwingWorker.java</a></p>
<p>[sourcecode language='java']<br />
public class Task{<br />
  public void go() {<br />
      current = 0;<br />
      final SwingWorker worker = new SwingWorker() {<br />
          public Object construct() {<br />
              return new ActualTask();<br />
          }<br />
      };<br />
  }</p>
<p>  class ActualTask {<br />
      ActualTask() {<br />
          try {<br />
              Thread.sleep(1000);<br />
          } catch (InterruptedException e) {}<br />
      }<br />
  }<br />
}<br />
[/sourcecode]</p>
<p>Task.java</p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2008/04/24/swingworker-not-on-java-60/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Java SE 6 Key Features</title>
		<link>http://technote.wsjoung.com/2006/12/13/java-se-6-key-features/</link>
		<comments>http://technote.wsjoung.com/2006/12/13/java-se-6-key-features/#comments</comments>
		<pubDate>Wed, 13 Dec 2006 06:54:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Features]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/12/13/java-se-6-key-features/</guid>
		<description><![CDATA[New Security Features and Enhancements Native platform Security (GSS/Kerberos) integration. Java Authentication and Authorization Service (JAAS) login module that employs LDAP authentication New Smart Card I/O API » Find out more Integrated Web Services New API for XML digital signature services for secure web services New Client and Core Java Architecture for XML-Web Services (JAX-WS) [...]]]></description>
			<content:encoded><![CDATA[<p><strong>New Security Features and Enhancements</strong></p>
<p><span class="sp10"> </span></p>
<ul>
<li>Native platform Security (GSS/Kerberos) integration.</li>
<li>Java Authentication and Authorization Service (JAAS) login module that employs LDAP authentication</li>
<li>New Smart Card I/O API<br />
<span class="rightarrowblue">»</span> <a href="http://java.sun.com/developer/technicalArticles/J2SE/security/">Find out more</a></li>
</ul>
<p><span class="sp10"> </span><br />
<strong>Integrated Web Services</strong></p>
<p><span class="sp10"> </span></p>
<ul>
<li>New API for XML digital signature services for secure web services</li>
<li>New Client and Core Java Architecture for XML-Web Services (JAX-WS) 2.0 APIs</li>
<li>New support for Java Architecture for XML Binding (JAXB) 2.0<br />
<span class="rightarrowblue">»</span> <a href="http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/">Find out more</a></li>
</ul>
<p><span class="sp10"> </span><br />
<strong>Scripting Language Support (<a href="http://jcp.org/en/jsr/detail?id=223" target="_blank">JSR 223</a>)</strong></p>
<p><span class="sp10"> </span></p>
<ul>
<li>New framework and API for scripting languages</li>
<li>Mozilla Rhino engine for JavaScript built into the platform<br />
<span class="rightarrowblue">»</span> <a href="http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/">Find out more</a></li>
</ul>
<p><span class="sp10"> </span><br />
<strong>Enhanced Management and Serviceability</strong></p>
<p><span class="sp10"> </span></p>
<ul>
<li>Improved JMX Monitoring API</li>
<li>Runtime Support for dTrace (Solaris 10 and future Solaris OS releases only)</li>
<li>Improved memory usage analysis and leak detection<br />
<span class="rightarrowblue">»</span> <a href="http://java.sun.com/developer/technicalArticles/J2SE/monitoring/">Find out more</a></li>
</ul>
<p><span class="sp10"> </span><br />
<strong>Increased Developer Productivity</strong></p>
<p><span class="sp10"> </span></p>
<ul>
<li>JDBC 4.0 support (<a href="http://jcp.org/en/jsr/detail?id=221" target="_blank">JSR 221</a>)</li>
<li>Significant library improvements</li>
<li>Improvements to the Java Platform Debug Architecture (JPDA) &amp; JVM Tool Interface</li>
</ul>
<p><span class="sp10"> </span><br />
<strong>Improved User Experience</strong></p>
<p><span class="sp10"> </span></p>
<ul>
<li>look-and-feel updates to better match underlying operating system</li>
<li>Improved desktop performance and integration</li>
<li>Enhanced internationalization support</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/12/13/java-se-6-key-features/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&quot;null&quot;, is this Object or not?</title>
		<link>http://technote.wsjoung.com/2006/11/26/null-is-this-object-or-not/</link>
		<comments>http://technote.wsjoung.com/2006/11/26/null-is-this-object-or-not/#comments</comments>
		<pubDate>Sun, 26 Nov 2006 08:15:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Null]]></category>
		<category><![CDATA[Object]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/null-is-this-object-or-not/</guid>
		<description><![CDATA[In java, some people say null is Object and they also use “null object” term when they try to explain something related in null like NullPointerException. And some people simply show “null instanceof Object” result to prove that null is not Object. Of course it returns false for “null instanceof Object”. Because null is technically [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">In java, some people say null is Object and they also use “null object” term when they try to explain something related in null like NullPointerException.</p>
<p class="MsoNormal">And some people simply show “null instanceof Object” result to prove that null is not Object. Of course it returns false for “null instanceof Object”. Because null is technically not Object.</p>
<p class="MsoNormal">The reason why people keep regarding null as a kind of Object is that they are confused those two terms, Object itself and Reference variable which points an object. Whenever they say “null object”, which means actually reference variable, and that reference variable assigned for a specific bit pattern which is for null.</p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/11/26/null-is-this-object-or-not/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Java Virtual Machine Tool Interface (JVMTI)</title>
		<link>http://technote.wsjoung.com/2006/11/17/the-java-virtual-machine-tool-interface-jvmti/</link>
		<comments>http://technote.wsjoung.com/2006/11/17/the-java-virtual-machine-tool-interface-jvmti/#comments</comments>
		<pubDate>Fri, 17 Nov 2006 01:03:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JVMTI]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/17/the-java-virtual-machine-tool-interface-jvmti/</guid>
		<description><![CDATA[JVMTI is a new native interface available in J2SDK1.5.0. JVMPI is still also available though, SUN plan to drop JVMPI soon or later. &#8220;JVMTI provides for all the functional capabilities of the previous native interfaces JVMDI and JVMPI. However, it does not have many of the limitations of those older interfaces. Some of the JVMPI [...]]]></description>
			<content:encoded><![CDATA[<p>JVMTI is a new native interface available in J2SDK1.5.0. JVMPI is still also available though, SUN plan to drop JVMPI soon or later.</p>
<p>&#8220;JVMTI provides for all the functional capabilities of the previous native interfaces JVMDI and JVMPI. However, it does not have many of the limitations of those older interfaces. Some of the JVMPI capabilities require the use of JVMTI and the technique called Byte Code Insertion (<a href="http://java.sun.com/developer/technicalArticles/Programming/jvmpitransition/index.html#BCI">BCI</a>), sometimes referred to as Byte Code Injection or Byte Code Instrumentation. JVMTI allows for all JVM functionality to continue to operate, like JIT or JVM compilation and different GC implementations. Certain JVMTI features are controlled by asking for JVMTI Capabilities, and some of these can cause changes in JVM performance, but most features are available while the JVM is running &#8220;full speed&#8221;. All JVMTI object handles are <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jni">JNI</a> handles, and JVMTI Event callbacks always include a <code>JNIEnv*</code> argument to facilitate JNI usage. Multiple JVMTI agents can operate in a single JVM and all interfaces return an error code to determine success or failure of the request. It is the intention of JVMTI to displace both JVMPI and JVMDI, and to ultimately be the single native tool interface into the JVM. &#8221; <a href="http://java.sun.com/developer/technicalArticles/Programming/jvmpitransition/index.html">The JVMPI Transition to JVMTI</a></p>
<p>There is my sample code.</p>
<p>simpleAgent.c</p>
<p>#include<br />
#include<br />
#include<br />
#include &#8220;jvmti.h&#8221;</p>
<p>static jvmtiEnv *jvmti = NULL;<br />
static jvmtiCapabilities capa;</p>
<p>//****** Implementation from here ******//</p>
<p>static void<br />
check_jvmti_error(jvmtiEnv *jvmti, jvmtiError errnum, const char *str)<br />
{<br />
if ( errnum != JVMTI_ERROR_NONE ) {<br />
char       *errnum_str;</p>
<p>errnum_str = NULL;<br />
(void)(*jvmti)-&gt;GetErrorName(jvmti, errnum, &amp;errnum_str);</p>
<p>printf(&#8220;ERROR: JVMTI: %d(%s): %s\n&#8221;, errnum, (errnum_str==NULL?&#8221;Unknown&#8221;:errnum_str), (str==NULL?&#8221;":str));<br />
}<br />
}</p>
<p>static void JNICALL<br />
callbackVMInit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread)<br />
{<br />
printf(&#8220;JVMTI_EVENT_VM_INIT is captured\n&#8221;);<br />
}</p>
<p>static void<br />
JNICALL callbackVMDeath(jvmtiEnv *jvmti_env, JNIEnv* jni_env)<br />
{<br />
printf(&#8220;JVMTI_EVENT_VM_DEATH is captured\n&#8221;);<br />
}</p>
<p>static void JNICALL<br />
callbackVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jobject object, jclass object_klass, jlong size)<br />
{<br />
printf(&#8220;JVMTI_EVENT_VM_OBJECT_ALLOC is captured:\n&#8221;);<br />
}</p>
<p>/* Agent_OnLoad() is called first, we prepare for a VM_INIT event here. */<br />
JNIEXPORT jint JNICALL<br />
Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)<br />
{</p>
<p>jint                res;<br />
jvmtiEventCallbacks callbacks;<br />
jvmtiError          error;</p>
<p>res = (*jvm)-&gt;GetEnv(jvm, (void **) &amp;jvmti, JVMTI_VERSION);</p>
<p>if (res != JNI_OK || jvmti == NULL) {<br />
/* This means that the VM was unable to obtain this version of the<br />
* JVMTI interface, this is a fatal error.<br />
*/<br />
printf(&#8220;ERROR: Unable to access JVMTI Version 1 (0x%x),&#8221;<br />
&#8221; is your J2SE a 1.5 or newer version?&#8221;<br />
&#8221; JNIEnv&#8217;s GetEnv() returned %d\n&#8221;,<br />
JVMTI_VERSION_1, res);</p>
<p>}</p>
<p>memset(&amp;capa, 0, sizeof(jvmtiCapabilities));<br />
error = (*jvmti)-&gt;GetPotentialCapabilities(jvmti, &amp;capa);<br />
if (error == JVMTI_ERROR_NONE) {<br />
error = (*jvmti)-&gt;AddCapabilities(jvmti, &amp;capa);<br />
check_jvmti_error(jvmti, error, &#8220;Unable to get necessary JVMTI capabilities.&#8221;);<br />
}</p>
<p>memset(&amp;callbacks, 0, sizeof(callbacks));<br />
callbacks.VMInit = &amp;callbackVMInit; /* JVMTI_EVENT_VM_INIT */<br />
callbacks.VMDeath = &amp;callbackVMDeath; /* JVMTI_EVENT_VM_DEATH */<br />
callbacks.VMObjectAlloc = &amp;callbackVMObjectAlloc;/* JVMTI_EVENT_VM_OBJECT_ALLOC */</p>
<p>error = (*jvmti)-&gt;SetEventCallbacks(jvmti, &amp;callbacks, (jint)sizeof(callbacks));<br />
check_jvmti_error(jvmti, error, &#8220;Cannot set jvmti callbacks&#8221;);</p>
<p>error = (*jvmti)-&gt;SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, (jthread)NULL);<br />
error = (*jvmti)-&gt;SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, (jthread)NULL);<br />
error = (*jvmti)-&gt;SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_OBJECT_ALLOC, (jthread)NULL);<br />
check_jvmti_error(jvmti, error, &#8220;Cannot set event notification&#8221;);</p>
<p>return JNI_OK;</p>
<p>}</p>
<p>/* Agent_OnUnload() is called last */<br />
JNIEXPORT void JNICALL<br />
Agent_OnUnload(JavaVM *vm)<br />
{<br />
}</p>
<p><a href="http://java.sun.com/j2se/1.5.0/docs/guide/jvmti/jvmti.html">JVMTI Reference</a></p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/11/17/the-java-virtual-machine-tool-interface-jvmti/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java memory management</title>
		<link>http://technote.wsjoung.com/2006/11/17/java-memory-management/</link>
		<comments>http://technote.wsjoung.com/2006/11/17/java-memory-management/#comments</comments>
		<pubDate>Fri, 17 Nov 2006 00:53:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Memory]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/17/java-memory-management/</guid>
		<description><![CDATA[JVM with the -verbose:gc or -Xloggc: a diagnostic message is printed on the console or to a log file every time the GC runs, including how long it took, the current heap usage, and how much memory was recovered. Logging GC usage is not intrusive, and so it is reasonable to enable GC logging in [...]]]></description>
			<content:encoded><![CDATA[<p><strong>JVM with the -verbose:gc</strong> or  -Xloggc:<br />
a diagnostic message is printed on the console or to a log file every time the GC runs, including how long it took, the current heap usage, and how much memory was recovered. Logging GC usage is not intrusive, and so it is reasonable to enable GC logging in production by default in the event you ever need to analyze memory problems or tune the garbage collector.</p>
<p><strong>JVM with the -Xrunhprof[:suboption=value]</strong><br />
Enables cpu, heap, or monitor profiling.<br />
java -Xrunhprof:help to obtain a list of suboptions and their default values.</p>
<p><strong><a href="http://java.sun.com/developer/technicalArticles/Programming/GCPortal/index.html">GC Portal</a></strong><br />
The GC Portal enables analysis and performance tuning of Java applications from a garbage collection (GC) perspective by mining the verbose:gc logs generated by the JVM.</p>
<p><strong><a href="http://www.hp.com/products1/unix/java/java2/hpjtune/">HPjtune</a></strong><br />
HPjtune is a Java Garbage Collection visualization tool for analyzing garbage collection activity in a Java program. The analysis is carried out off-line or on-line, based on the output of the JVM via the -Xloggc or -Xverbosegc output file.</p>
<p><a href="http://java.sun.com/docs/hotspot/VMOptions.html">JavaTM HotSpot VM Options</a></p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/11/17/java-memory-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Feature, Graph3D</title>
		<link>http://technote.wsjoung.com/2006/05/27/java-feature-graph3d/</link>
		<comments>http://technote.wsjoung.com/2006/05/27/java-feature-graph3d/#comments</comments>
		<pubDate>Sat, 27 May 2006 18:23:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[3D]]></category>

		<guid isPermaLink="false">https://wsjoung.wordpress.com/2006/05/27/java-feature-graph3d/</guid>
		<description><![CDATA[My current research obviously need to handle 3D graph. actually it just a graph. basically I need to compare those 3D images then I should choose the most common one. I am still working on it. I hope that this Java 3D features are good for my work. Java Feature — Graph3D In today&#8217;s work [...]]]></description>
			<content:encoded><![CDATA[<p>My current research obviously need to handle 3D graph. actually it just a graph. basically I need to compare those 3D images then I should choose the most common one. I am still working on it.</p>
<p>I hope that this Java 3D features are good for my work.</p>
<blockquote><p><a href="http://www.java.sys-con.com/read/216381.htm">Java Feature — Graph3D</a> In today&#8217;s work environment analyzing large amounts of varying data types is paramount. Graphing techniques can be an invaluable tool to understanding and interpreting that data. In many cases two-dimensional graphs, such as XY, scatter, pie, and bar charts, are sufficient. But increasingly more complex graphing techniques are needed. In these instances Java3D is an excellent resource with numerous features that allow personalized generation of three-dimensional data displays. Not only will Java3D yield better insight into the data by highlighting important aspects of the data, but it also makes attractive displays to spice up any presentation.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/05/27/java-feature-graph3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
