<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">
<channel><title>Official Blog of Michael Liao</title><link>http://michael-liao.appspot.com/feed.xml</link><description>Java and Python developer</description><pubDate>Thu, 05 Nov 2009 09:29:17 +0000</pubDate><generator>expressme.org</generator><language>en</language><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/michael-liao" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="michael-liao" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>Be careful when using Timer</title><link>http://michael-liao.appspot.com/it/47253e2096114567813fde72c1d7c278</link><dc:creator>Michael Liao</dc:creator><pubDate>Thu, 05 Nov 2009 09:29:17 +0000</pubDate><description>&lt;p&gt;Timer is used to schedule tasks that run at a fixed rate in Java. However, the thread of Timer itself may stop unexpected when your TimerTask throws an uncaught exception. See following code:&lt;/p&gt;
&lt;pre class="brush:java"&gt;
public class TimerTest {

    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(
                new TimerTask() {
                    int n = 0;
                    @Override
                    public void run() {
                        if (n==10)
                            throw new RuntimeException(&amp;quot;task failed.&amp;quot;);
                        System.out.print('.');
                        n++;
                    }
                },
                1000L,
                1000L
        );
    }
}
&lt;/pre&gt;
&lt;p&gt;When the TimerTask runs 10 times it throws a RuntimeException, which cause the thread of Timer stopped. You will get the following output:&lt;/p&gt;
&lt;pre class="brush:java"&gt;
..........Exception in thread &amp;quot;Timer-0&amp;quot; java.lang.RuntimeException: task failed.
	at sync.test.TimerTest$1.run(TimerTest.java:16)
	at java.util.TimerThread.mainLoop(Timer.java:512)
	at java.util.TimerThread.run(Timer.java:462)
&lt;/pre&gt;
&lt;p&gt;It is necessary to catch all exceptions in TimerTask. But the best way to schedule tasks is using Executor if you are working with JDK 5 or later. It is fast, with pooled thread, and more simple API to schedule tasks.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Jhum0S7ywMzUis99I0D0oXtuCH0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Jhum0S7ywMzUis99I0D0oXtuCH0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Jhum0S7ywMzUis99I0D0oXtuCH0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Jhum0S7ywMzUis99I0D0oXtuCH0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description></item>
<item><title>JexiEditor: a WYSIWYG Editor</title><link>http://michael-liao.appspot.com/it/c2027e30aa2844fea4e506960ffe7837</link><dc:creator>Michael Liao</dc:creator><pubDate>Fri, 16 Oct 2009 07:49:32 +0000</pubDate><description>&lt;p&gt;JexiEditor is a WYSIWYG (what you see is what you get) editor written by Java. It is a very good example of learning the famous &amp;quot;&lt;a target="_blank" href="http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612"&gt;GoF: Design Patterns&lt;/a&gt;&amp;quot;.&lt;/p&gt;
&lt;p&gt;The source code can be downloaded or checked out from SVN. Please visit the project home page:&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://code.google.com/p/jexieditor/"&gt;http://code.google.com/p/jexieditor/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The word &amp;quot;Jexi&amp;quot; is a combination of &amp;quot;Java&amp;quot; and &amp;quot;Lexi&amp;quot;. See snapshot:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://michael-liao.appspot.com/proxy?url=http://lh6_ggpht_com/_Q_A6LQBcREQ/StgjPunrzvI/AAAAAAAAAy8/m79Rx-TYGSk/snapshot.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/frC4Zo6MnNdFvaJtNg0dQe50mtk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/frC4Zo6MnNdFvaJtNg0dQe50mtk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/frC4Zo6MnNdFvaJtNg0dQe50mtk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/frC4Zo6MnNdFvaJtNg0dQe50mtk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description></item>
<item><title>JOpenID: OpenID 2.0 Client Library for Java</title><link>http://michael-liao.appspot.com/it/f6568e3e47074d3b8922124354391767</link><dc:creator>Michael Liao</dc:creator><pubDate>Fri, 16 Oct 2009 07:36:58 +0000</pubDate><description>&lt;p&gt;JOpenID is a lightweight Java client library of &lt;a target="_blank" href="http://openid.net/"&gt;OpenID 2.0&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;JOpenID supports sign on by OpenID 2.0 protocol, which enables user to sign on with their OpenID account without registration on your website. The well-known OpenID providers are Google account, Yahoo account, etc.&lt;/p&gt;
&lt;p&gt;JOpenID is simple, fast and very small, about &lt;strong&gt;50 KB&lt;/strong&gt; including both binary and source code. You can download from:&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://code.google.com/p/jopenid/downloads/list"&gt;http://code.google.com/p/jopenid/downloads/list&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For more information about JOpenID, please visit the project home page:&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://code.google.com/p/jopenid/"&gt;http://code.google.com/p/jopenid/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;JOpenID is now on the list of recommended libraries on &lt;a target="_blank" href="http://openid.net/"&gt;OpenID official website&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://michael-liao.appspot.com/proxy?url=http://lh5_ggpht_com/_Q_A6LQBcREQ/StVvOOkXYnI/AAAAAAAAAyc/8A2CoHcNlg4/jopenid.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kOirLElHkGvQN97qrDs4LW9WoIY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kOirLElHkGvQN97qrDs4LW9WoIY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kOirLElHkGvQN97qrDs4LW9WoIY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kOirLElHkGvQN97qrDs4LW9WoIY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description></item>
<item><title>How to use OpenID to sign on with Google account</title><link>http://michael-liao.appspot.com/it/35220c97f4524e38864e062edf55d1a4</link><dc:creator>Michael Liao</dc:creator><pubDate>Wed, 14 Oct 2009 05:40:46 +0000</pubDate><description>&lt;p&gt;Recently Google announced its support for OpenID, called &amp;quot;&lt;a target="_blank" href="http://code.google.com/apis/accounts/docs/OpenID.html"&gt;Federated Login&lt;/a&gt;&amp;quot;, to let any site enable their users to sign on by their Google accounts, without registrations.&lt;/p&gt;
&lt;p&gt;This is really a good news, and for Java developers they can write some code to make the 3rd-part site to connect to Google. There are already lots of libaries that can be used in J2EE. However, after I do some evaluation of these libaries, I do not find a suitable libary. The well-known &amp;quot;&lt;a target="_blank" href="http://code.sxip.com/openid4java/"&gt;OpenID4Java&lt;/a&gt;&amp;quot;, is too large (46MB!), with dependencies on many other libaries. So I decided to write a small, but very lightweight libary to support OpenID 2.0 spec, called &amp;quot;&lt;a target="_blank" href="http://code.google.com/p/jopenid/"&gt;JOpenID&lt;/a&gt;&amp;quot;.&lt;/p&gt;
&lt;p&gt;It is very small, about 50KB including both source &amp;amp; binary. You can download from:&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://code.google.com/p/jopenid/downloads/list"&gt;http://code.google.com/p/jopenid/downloads/list&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It only depends &lt;a target="_blank" href="http://commons.apache.org/logging/"&gt;commons-logging&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;Sample code is provided:&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://code.google.com/p/jopenid/source/browse/trunk/JOpenId/src/com/javaeedev/openid/Main.java"&gt;http://code.google.com/p/jopenid/source/browse/trunk/JOpenId/src/com/javaeedev/openid/Main.java&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It has been fully tested based on Google accounts. However, I think it also can support Yahoo! OpenID, but with little information provided by Yahoo! I do not test yet.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/FgtlKo97LAQsc_nd7EjVKoXfFJA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FgtlKo97LAQsc_nd7EjVKoXfFJA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/FgtlKo97LAQsc_nd7EjVKoXfFJA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FgtlKo97LAQsc_nd7EjVKoXfFJA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description></item>
<item><title>About Michael Liao</title><link>http://michael-liao.appspot.com/it/4b1b19cb6f8749208a1c12f18243c729</link><dc:creator>Michael Liao</dc:creator><pubDate>Wed, 14 Oct 2009 03:26:32 +0000</pubDate><description>&lt;p&gt;Hi, I'm Michael Liao, a software engineer in China.&lt;/p&gt;
&lt;p&gt;I have 5 years experiences in software development, especially Java and Python.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zj9EaVsZdUm_drxIGNNHQLWFi8g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zj9EaVsZdUm_drxIGNNHQLWFi8g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zj9EaVsZdUm_drxIGNNHQLWFi8g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zj9EaVsZdUm_drxIGNNHQLWFi8g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description></item>
</channel></rss>

