<?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>vifix.cn &#187; Atelier</title>
	<atom:link href="http://vifix.cn/blog/category/atelier/feed" rel="self" type="application/rss+xml" />
	<link>http://vifix.cn/blog</link>
	<description>compile the dream, compile tomorrow</description>
	<lastBuildDate>Tue, 15 May 2012 11:42:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>HTML5 修改浏览器url而不刷新页面</title>
		<link>http://vifix.cn/blog/html5-modify-browser-url-without-reloading-page.html</link>
		<comments>http://vifix.cn/blog/html5-modify-browser-url-without-reloading-page.html#comments</comments>
		<pubDate>Tue, 07 Feb 2012 05:46:18 +0000</pubDate>
		<dc:creator>Mac</dc:creator>
				<category><![CDATA[Atelier]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://vifix.cn/blog/?p=2238</guid>
		<description><![CDATA[嘛，起因是黑子大叔在微博上的一条@信息，找起了这个的实现，看了一圈google的中文信息内似乎还没有怎么提到这个的内容，就发表上来。 详细效果就是类似于用Firefox4+/Chrome 5+/Safari 5+/Opera 11.5+登录新浪微博后看到的个人时间轴，在翻页时可以观察到这个效果，地址栏URL变动，但是页面没有刷新，用firebug观察也观察不到刷新整个页面，只有ajax请求的翻页数据。从先前的理解来说，URL的修改必然引起（请注意我不是在说通过锚点修改）浏览器重载页面，但利用HTML5新加入的history.pushState();和history.replaceState();可以完全自己维护一个历史记录列表绕开历史记录完全由浏览器控制的机制，从而实现比锚点更加完美的一种页内更新的体验。 代码方面很简单，只要在需要修改url的地方插入一行： window.history.pushState&#40;&#123;&#34;html&#34;:response.html,&#34;pageTitle&#34;:response.pageTitle&#125;, 'title', urlPath&#41;; //三个参数，分别为：状态对象，标题（目前被浏览器忽略），地址 即可在历史记录里面产生一个新的历史记录（另一个replaceState方法参数完全相同，只是替代掉当前的状态）。 在体验上，非常接近于使用锚点（window.location = &#8220;#foo&#8221;;），但是mozilla的文档提出了以下三点好处： 新的URL可以是和原始页面URL同域下的任何URL，如果用锚点，只能更新#后面的部分 仅在需要时更新URL，锚点的历史记录在相同时不会创建（即当前已经是&#8221;#foo&#8221;的情况下，如果再将当前页面锚点设置为&#8221;#foo&#8221;，不会产生新的历史记录） 可以记录下任意类型的数据，使用锚点的话将要自己维护一份历史数据列表或者把数据转码到一个字符串里 （翻译&#038;描述的有点别扭，见笑了，不过其实应该自己也能体会到这些好处才是） 我自己实现的一个例子： http://vifix.cn/atelier/demos/html5-update-browser-url-without-reloading-page 代码： &#60;?php if&#40;!isset&#40;$_REQUEST&#91;'page'&#93;&#41;&#41;&#123; $page = 1; &#125; else&#123; $page = intval&#40;$_REQUEST&#91;'page'&#93;&#41;; &#125; &#160; if&#40;isset&#40;$_REQUEST&#91;'ajaxload'&#93;&#41;&#41;&#123; echo &#34;第{$page}页的内容&#34;; die; &#125; ?&#62; &#60;!DOCTYPE html&#62; &#60;html&#62; &#60;head&#62; &#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=UTF-8&#34; /&#62; &#60;title&#62;HTML5 修改浏览器url而不刷新页面&#60;/title&#62; &#60;script type=&#34;text/javascript&#34;&#62; var domLoaded = [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://vifix.cn/blog/wp-content/uploads/2012/02/HTML5_Logo_512.png" rel="shadowbox[sbpost-2238];player=img;" title="HTML5_Logo_512"><img class="alignnone size-thumbnail wp-image-2239" title="HTML5_Logo_512" src="http://vifix.cn/blog/wp-content/uploads/2012/02/HTML5_Logo_512-150x150.png" alt="" width="150" height="150" /></a></p>
<p>嘛，起因是黑子大叔在微博上的一条@信息，找起了这个的实现，看了一圈google的中文信息内似乎还没有怎么提到这个的内容，就发表上来。</p>
<p>详细效果就是类似于用Firefox4+/Chrome 5+/Safari 5+/Opera 11.5+登录新浪微博后看到的个人时间轴，在翻页时可以观察到这个效果，地址栏URL变动，但是页面没有刷新，用firebug观察也观察不到刷新整个页面，只有ajax请求的翻页数据。从先前的理解来说，URL的修改必然引起（请注意我不是在说通过锚点修改）浏览器重载页面，但利用HTML5新加入的<strong>history.pushState();</strong>和<strong>history.replaceState();</strong>可以完全自己维护一个历史记录列表绕开历史记录完全由浏览器控制的机制，从而实现比锚点更加完美的一种页内更新的体验。</p>
<p>代码方面很简单，只要在需要修改url的地方插入一行：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">history</span>.<span style="color: #660066;">pushState</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;html&quot;</span><span style="color: #339933;">:</span>response.<span style="color: #660066;">html</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;pageTitle&quot;</span><span style="color: #339933;">:</span>response.<span style="color: #660066;">pageTitle</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'title'</span><span style="color: #339933;">,</span> urlPath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//三个参数，分别为：状态对象，标题（目前被浏览器忽略），地址</span></pre></div></div>

<p>即可在历史记录里面产生一个新的历史记录（另一个<strong>replaceState</strong>方法参数完全相同，只是替代掉当前的状态）。<br />
在体验上，非常接近于使用锚点（<strong>window.location = &#8220;#foo&#8221;;</strong>），但是mozilla的文档提出了以下三点好处：</p>
<ul>
<li>新的URL可以是和原始页面URL同域下的任何URL，如果用锚点，只能更新#后面的部分</li>
<li>仅在需要时更新URL，锚点的历史记录在相同时不会创建（即当前已经是&#8221;#foo&#8221;的情况下，如果再将当前页面锚点设置为&#8221;#foo&#8221;，不会产生新的历史记录）</li>
<li>可以记录下任意类型的数据，使用锚点的话将要自己维护一份历史数据列表或者把数据转码到一个字符串里</li>
</ul>
<p>（翻译&#038;描述的有点别扭，见笑了，不过其实应该自己也能体会到这些好处才是）</p>
<p>我自己实现的一个例子：<br />
<a href="http://vifix.cn/atelier/demos/html5-update-browser-url-without-reloading-page" target="_blank">http://vifix.cn/atelier/demos/html5-update-browser-url-without-reloading-page</a></p>
<p><span id="more-2238"></span></p>
<p>代码：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ajaxload'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;第<span style="color: #006699; font-weight: bold;">{$page}</span>页的内容&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">die</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
&lt;title&gt;HTML5 修改浏览器url而不刷新页面&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var domLoaded = function(){
	if(ua != null &amp;&amp; ua[1] &lt; 10){
		alert('您的浏览器不支持');
		return ;
	}
&nbsp;
	if(location.href.indexOf(&quot;?&quot;) &gt; -1){
		var urlparts = location.href.match(/(.+?)\?.+/i);
		var urlbase = urlparts[1];
	}
	else{
		var urlbase = location.href;
	}
	var page = <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$page</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>;
	var ua = window.navigator.userAgent.match(/msie (\d\.\d)/i);
	var content = document.getElementById(&quot;content&quot;);
	var loading = document.getElementById(&quot;loading&quot;);
&nbsp;
	window.history.replaceState(
		{
			content:content.innerHTML,
			page:page
		},
		page,
		urlbase + (page &gt; 1 ? '?page=' + page : '' )
	);
&nbsp;
	var ajax = new XMLHttpRequest();
	var ajaxCallback = function(){
		if(ajax.readyState == 4){
			loading.style.display = 'none';
			content.innerHTML = ajax.responseText;
			window.history.pushState(
				{
					content:content.innerHTML,
					page:page
				},
				page,
				urlbase + &quot;?page=&quot; + page
			);
			next.href = urlbase + &quot;?page=&quot; + (page + 1);
		}
	};
&nbsp;
	var next = document.getElementById('next');
	var nextClickEvent = function(event){
		if(loading.style.display != 'block'){
			loading.style.display = 'block';
			page++;
			ajax.open('GET', urlbase + '?page=' + page + '&amp;ajaxload=on', true);
			ajax.onreadystatechange = ajaxCallback;
			ajax.send('');
			event.preventDefault();
		}
	};
	next.addEventListener('click', nextClickEvent, false);
&nbsp;
	var popstate = function(){
		content.innerHTML = history.state.content;
		page = history.state.page;
	};
	window.addEventListener('popstate', popstate, false);
};
&nbsp;
try{
	window.addEventListener('DOMContentLoaded', domLoaded, false);
}
catch(e){
	alert('您的浏览器不支持');	
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;p id=&quot;content&quot;&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;第<span style="color: #006699; font-weight: bold;">{$page}</span>页的内容&quot;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/p&gt;
	&lt;p&gt;
		&lt;a id=&quot;next&quot; href=&quot;?page=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$page</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;下一页&lt;/a&gt;
	&lt;/p&gt;
	&lt;div id=&quot;loading&quot; style=&quot;display:none;&quot;&gt;
		加载中
	&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>mozilla的文档<br />
<a href="https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history" target="_blank" onclick="pageTracker._trackPageview('/outgoing/developer.mozilla.org/en/DOM/Manipulating_the_browser_history?referer=');">https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history</a></p>
<p>stackoverflow上的相关问题：<br />
<a href="http://stackoverflow.com/questions/3338642/updating-address-bar-with-new-url-without-hash-or-reloading-the-page" target="_blank" onclick="pageTracker._trackPageview('/outgoing/stackoverflow.com/questions/3338642/updating-address-bar-with-new-url-without-hash-or-reloading-the-page?referer=');">http://stackoverflow.com/questions/3338642/updating-address-bar-with-new-url-without-hash-or-reloading-the-page</a><br />
<a href="http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page" target="_blank" onclick="pageTracker._trackPageview('/outgoing/stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page?referer=');">http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page</a></p>
]]></content:encoded>
			<wfw:commentRss>http://vifix.cn/blog/html5-modify-browser-url-without-reloading-page.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SimpleSnake &#8211; Hello, Android World</title>
		<link>http://vifix.cn/blog/simplesnake-hello-android-world.html</link>
		<comments>http://vifix.cn/blog/simplesnake-hello-android-world.html#comments</comments>
		<pubDate>Fri, 20 Jan 2012 06:39:13 +0000</pubDate>
		<dc:creator>Mac</dc:creator>
				<category><![CDATA[Atelier]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://vifix.cn/blog/?p=2229</guid>
		<description><![CDATA[年末了，相对来说工作已经比较清闲，于是趁着机会研究了一下Android的游戏开发，花了一个下午写了这个贪吃蛇的应用。 使用的游戏引擎是libgdx，虽然目前看起来文档比较缺少，但是，最大的好处是可以在Winodows/OSX/Linux上运行，android上则只需要额外几行代码就可以运行，极大的方便了调试和跨平台的工作。 下载apk请点击此处 &#8211; simplesnake （必须要800&#215;480的分辨率才可以正常运行，如果大于这个分辨率仍然可以运行但按钮将错位，低于这个分辨率则可能出现奇怪的问题并且按钮缺失，因为只是hello, world，所以也不打算进一步优化各个分辨率了） 另外推荐下libgdx原作者的博客badlogic，以及他写的书：google book，豆瓣，像我这样的游戏开发初学者看看挺不错的。 一篇国产PC/Android游戏引擎LGame作者cping1982同学的介绍libgx的科普文章也很值得一看：http://blog.csdn.net/cping1982/article/details/6176191]]></description>
			<content:encoded><![CDATA[<p><a href="http://vifix.cn/blog/wp-content/uploads/2012/01/simple-snake.png" rel="shadowbox[sbpost-2229];player=img;"><img class="alignnone size-medium wp-image-2230" src="http://vifix.cn/blog/wp-content/uploads/2012/01/simple-snake-300x276.png" alt="" width="300" height="276" /></a></p>
<p>年末了，相对来说工作已经比较清闲，于是趁着机会研究了一下Android的游戏开发，花了一个下午写了这个贪吃蛇的应用。</p>
<p>使用的游戏引擎是<a href="http://code.google.com/p/libgdx/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/libgdx/?referer=');">libgdx</a>，虽然目前看起来文档比较缺少，但是，最大的好处是可以在Winodows/OSX/Linux上运行，android上则只需要额外几行代码就可以运行，极大的方便了调试和跨平台的工作。</p>
<p>下载apk请点击此处 &#8211; <a href="http://vifix.cn/blog/wp-content/uploads/2012/01/simplesnake.zip">simplesnake</a> （必须要800&#215;480的分辨率才可以正常运行，如果大于这个分辨率仍然可以运行但按钮将错位，低于这个分辨率则可能出现奇怪的问题并且按钮缺失，因为只是hello, world，所以也不打算进一步优化各个分辨率了）</p>
<p>另外推荐下libgdx原作者的博客<a href="http://badlogicgames.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/badlogicgames.com/?referer=');">badlogic</a>，以及他写的书：<a href="http://books.google.com.hk/books?id=NetBrvVEe3cC&amp;printsec=frontcover&amp;dq=beginning+android+game&amp;hl=en&amp;sa=X&amp;ei=HAsZT_2IJM2ciQf6ronWCw&amp;redir_esc=y&amp;hl=zh-CN&amp;sourceid=cndr#v=onepage&amp;q&amp;f=false" target="_blank" onclick="pageTracker._trackPageview('/outgoing/books.google.com.hk/books?id=NetBrvVEe3cC_amp_printsec=frontcover_amp_dq=beginning+android+game_amp_hl=en_amp_sa=X_amp_ei=HAsZT_2IJM2ciQf6ronWCw_amp_redir_esc=y_amp_hl=zh-CN_amp_sourceid=cndr_v=onepage_amp_q_amp_f=false&amp;referer=');">google book</a>，<a href="http://book.douban.com/subject/4753615/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/book.douban.com/subject/4753615/?referer=');">豆瓣</a>，像我这样的游戏开发初学者看看挺不错的。</p>
<p>一篇国产PC/Android游戏引擎LGame作者cping1982同学的介绍libgx的科普文章也很值得一看：<a href="http://blog.csdn.net/cping1982/article/details/6176191" target="_blank" onclick="pageTracker._trackPageview('/outgoing/blog.csdn.net/cping1982/article/details/6176191?referer=');">http://blog.csdn.net/cping1982/article/details/6176191</a></p>
]]></content:encoded>
			<wfw:commentRss>http://vifix.cn/blog/simplesnake-hello-android-world.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>吃巧克力节没人约无处去只好毁歌有感（？）</title>
		<link>http://vifix.cn/blog/happy-valentine-20100214.html</link>
		<comments>http://vifix.cn/blog/happy-valentine-20100214.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 14:59:15 +0000</pubDate>
		<dc:creator>Mac</dc:creator>
				<category><![CDATA[Atelier]]></category>
		<category><![CDATA[Otaku]]></category>
		<category><![CDATA[orz]]></category>

		<guid isPermaLink="false">http://vifix.cn/blog/?p=1352</guid>
		<description><![CDATA[那么标题图是今天基友呃不对宅友送的宅物，konata一只，当然了，还有konata手上的好人卡，嗯（严重误） 于是下面是一年一度的自娱自乐和毁灭狗耳计划…… ===警告=== 继续阅读此帖可能会引起大脑神经短路，狗耳烧坏等不适症状，请务必自备避雷针和氪金狗耳后再考虑进入 orzorzorzorz 歌曲选的是Valentine Kiss的网球王子的一个声优的版本，这歌本身是老歌了，没记错的话，是1985年的歌了，原唱是国生小百合，自Lucky Star的Tsukasa酱在ending的卡拉OK里面唱了一遍后被萌到。 但请注意这里的物体： 渣演唱 渣混音 渣剪辑（完整版有3分半，发现后面的自己今天是唱不下来了，就瞎剪了……） 链接在此（点击后在线播放） （flash播放器的下载以及缓冲可能会较慢…… 对于一切因为以上mp3造成的伤害本人概不负责 orz 好吧这是去年的传送门…… 大年初一的出来吓人，真是对不起各位了TVTbbb]]></description>
			<content:encoded><![CDATA[<p><a href="http://vifix.cn/blog/wp-content/uploads/2010/02/IMG_6610.jpg" rel="shadowbox[sbpost-1352];player=img;" title="IMG_6610"><img class="alignnone size-medium wp-image-1353" title="IMG_6610" src="http://vifix.cn/blog/wp-content/uploads/2010/02/IMG_6610-200x300.jpg" alt="" width="200" height="300" /></a></p>
<p>那么标题图是今天<span style="text-decoration: line-through;">基友</span>呃不对宅友送的宅物，konata一只，当然了，还有konata手上的好人卡，嗯（严重误）</p>
<p><span style="text-decoration: line-through;">于是下面是一年一度的自娱自乐和毁灭狗耳计划……</span></p>
<p><span style="color: #ff0000;">===警告===</span></p>
<p>继续阅读此帖可能会引起大脑神经短路，狗耳烧坏等不适症状，请务必自备避雷针和氪金狗耳后再考虑进入 orzorzorzorz</p>
<p><span id="more-1352"></span>歌曲选的是Valentine Kiss的网球王子的一个声优的版本，这歌本身是老歌了，没记错的话，是1985年的歌了，原唱是国生小百合，自Lucky Star的Tsukasa酱在ending的卡拉OK里面唱了一遍后被萌到。</p>
<p>但请注意这里的物体：</p>
<ul>
<li>渣演唱</li>
<li>渣混音</li>
<li>渣剪辑（完整版有3分半，发现后面的自己今天是唱不下来了，就瞎剪了……）</li>
</ul>
<p><a href="http://vifix.cn/blog/wp-content/uploads/2010/02/Valentine-Kiss.mp3" rel="shadowbox[sbpost-1352];player=flv;width=500;height=0;">链接在此（点击后在线播放）</a> （flash播放器的下载以及缓冲可能会较慢……</p>
<p>对于一切因为以上mp3造成的伤害本人概不负责 orz</p>
<p>好吧这是<a href="http://vifix.cn/blog/happy-valentine-20090214.html" target="_self">去年的传送门</a>……</p>
<p>大年初一的出来吓人，真是对不起各位了TVTbbb</p>
]]></content:encoded>
			<wfw:commentRss>http://vifix.cn/blog/happy-valentine-20100214.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
<enclosure url="http://vifix.cn/blog/wp-content/uploads/2010/02/Valentine-Kiss.mp3" length="1462072" type="audio/mpeg" />
		</item>
		<item>
		<title>新的主题，新的开始</title>
		<link>http://vifix.cn/blog/new-wordpress-theme-new-beginning.html</link>
		<comments>http://vifix.cn/blog/new-wordpress-theme-new-beginning.html#comments</comments>
		<pubDate>Sun, 31 Jan 2010 16:03:12 +0000</pubDate>
		<dc:creator>Mac</dc:creator>
				<category><![CDATA[Atelier]]></category>
		<category><![CDATA[Website]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://vifix.cn/blog/?p=1331</guid>
		<description><![CDATA[总之，效果想必点击进来的也已经看到了，实际上这个主题我连名字也没有认真的想，一想现在是冬天，就随手命名成了vifix-winter。虽说春天都快到了。 使用了很多CSS 3.0的特性，所以在Firefox 3.5+和Chrome以及Safari的最新版本上才可以看到最好的效果。一些特性IE8上也得不到支持，写了专门的CSS修正，更不要说那个诡异的IE6了，所以IE6上访问本站将是一个缩水后的版本（并且还会有一个简单的提示） orz 背景的蓝色渐变是纯天然的，就是上面照片中的最右边的一个像素宽的内容，2009年10月摄于南京。]]></description>
			<content:encoded><![CDATA[<p><a href="http://vifix.cn/blog/wp-content/uploads/2010/02/IMG_3553.jpg" rel="shadowbox[sbpost-1331];player=img;" title="IMG_3553"><img class="alignnone size-medium wp-image-1332" title="IMG_3553" src="http://vifix.cn/blog/wp-content/uploads/2010/02/IMG_3553-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>总之，效果想必点击进来的也已经看到了，实际上这个主题我连名字也没有认真的想，一想现在是冬天，就随手命名成了vifix-winter。虽说春天都快到了。</p>
<p>使用了很多CSS 3.0的特性，所以在Firefox 3.5+和Chrome以及Safari的最新版本上才可以看到最好的效果。一些特性IE8上也得不到支持，写了专门的CSS修正，更不要说那个诡异的IE6了，所以IE6上访问本站将是一个缩水后的版本（并且还会有一个简单的提示） orz</p>
<p>背景的蓝色渐变是纯天然的，就是上面照片中的最右边的一个像素宽的内容，2009年10月摄于南京。</p>
]]></content:encoded>
			<wfw:commentRss>http://vifix.cn/blog/new-wordpress-theme-new-beginning.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>利用Google Map API获取地址坐标</title>
		<link>http://vifix.cn/blog/convert-address-to-coordinates-google-map-api.html</link>
		<comments>http://vifix.cn/blog/convert-address-to-coordinates-google-map-api.html#comments</comments>
		<pubDate>Sat, 06 Jun 2009 14:41:29 +0000</pubDate>
		<dc:creator>Mac</dc:creator>
				<category><![CDATA[Atelier]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://vifix.cn/blog/?p=941</guid>
		<description><![CDATA[朋友拜托改的一段PHP小代码，其实就是Google MAP API FAQ里面提到的例子稍作修改，原文例子还用到了MySQL作为存储因此扯了一堆MySQL和PHPMyAdmin，只是想简单查下的就显得没必要了。 修改 @ 2009-06-07 : 于是今天写了一个Javascript版本的：http://vifix.cn/atelier/address_to_coordinates/ ，代码都在HTML里面了，感兴趣可以右键查看源码。 下面是PHP版本的代码： define&#40;&#34;MAPS_HOST&#34;, &#34;maps.google.com&#34;&#41;; define&#40;&#34;KEY&#34;, &#34;更换成你的KEY，可以去 http://code.google.com/intl/zh-CN/apis/maps/signup.html 申请&#34;&#41;; $base_url = &#34;http://&#34; . MAPS_HOST . &#34;/maps/geo?output=xml&#34; . &#34;&#38;amp;key=&#34; . KEY; $address = &#34;上海东方明珠塔&#34;; // 需要查询的地址 $request_url = $base_url . &#34;&#38;amp;q=&#34; . urlencode&#40;$address&#41;; $xml = simplexml_load_file&#40;$request_url&#41; or die&#40;&#34;url not loading&#34;&#41;; &#160; $status = $xml-&#38;gt;Response-&#38;gt;Status-&#38;gt;code; if &#40;strcmp&#40;$status, &#34;200&#34;&#41; == [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="attachment wp-att-196" href="http://vifix.cn/blog/google%e5%a8%98%ef%bd%9e.html/googlecom" title="Google.com"><img class="alignnone size-full wp-image-196" title="Google.com" src="http://vifix.cn/blog/wp-content/uploads/2008/11/googlecom.png" alt="Google.com" width="135" height="200" /></a></p>
<p>朋友拜托改的一段PHP小代码，其实就是<a href="http://code.google.com/intl/zh-CN/apis/maps/articles/phpsqlgeocode.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/code.google.com/intl/zh-CN/apis/maps/articles/phpsqlgeocode.html?referer=');">Google MAP API FAQ里面提到的例子</a>稍作修改，原文例子还用到了MySQL作为存储因此扯了一堆MySQL和PHPMyAdmin，只是想简单查下的就显得没必要了。</p>
<h3>修改 @ 2009-06-07 :</h3>
<p>于是今天写了一个Javascript版本的：<a href="http://vifix.cn/atelier/address_to_coordinates/">http://vifix.cn/atelier/address_to_coordinates/<br />
</a>，代码都在HTML里面了，感兴趣可以右键查看源码。</p>
<p>下面是PHP版本的代码：<br />
<span id="more-941"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MAPS_HOST&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;maps.google.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;KEY&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;更换成你的KEY，可以去 http://code.google.com/intl/zh-CN/apis/maps/signup.html 申请&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$base_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span> <span style="color: #339933;">.</span> MAPS_HOST <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/maps/geo?output=xml&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;amp;key=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">KEY</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$address</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;上海东方明珠塔&quot;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// 需要查询的地址</span>
<span style="color: #000088;">$request_url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$base_url</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;amp;q=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request_url</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;url not loading&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Response<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Status<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>code<span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strcmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;200&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Successful geocode</span>
	<span style="color: #000088;">$geocode_pending</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$coordinates</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Response<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Placemark<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Point<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>coordinates<span style="color: #339933;">;</span>
	<span style="color: #000088;">$coordinatesSplit</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$coordinates</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Format: Longitude, Latitude, Altitude</span>
	<span style="color: #000088;">$lat</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$coordinatesSplit</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$lng</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$coordinatesSplit</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;坐标: <span style="color: #006699; font-weight: bold;">$lat</span>,<span style="color: #006699; font-weight: bold;">$lng</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strcmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;620&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;请求频率过快&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;请求失败&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://vifix.cn/blog/convert-address-to-coordinates-google-map-api.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>一个PHP简易访问计数</title>
		<link>http://vifix.cn/blog/ezcounter.html</link>
		<comments>http://vifix.cn/blog/ezcounter.html#comments</comments>
		<pubDate>Sun, 31 May 2009 12:52:18 +0000</pubDate>
		<dc:creator>Mac</dc:creator>
				<category><![CDATA[Atelier]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://vifix.cn/blog/?p=922</guid>
		<description><![CDATA[嘛，受朋友所托写的，不是什么大不了的东西，贴上来就当给初学者参考吧 只有计数功能，利用session防止重复计数 注意只能运行在PHP5+上 代码见页内： /** * ezcounter * http://vifix.cn * MIT Lisence */ &#160; class ezcounter&#123; &#160; const display_only = 1; const display_and_count = 0; &#160; private $file; private $hits; &#160; // 构造函数 public function __construct&#40;$name = 'ezcounter'&#41;&#123; &#160; // 存放计数的文件 $this-&#62;file = dirname&#40;__FILE__&#41; . &#34;/$name.txt&#34;; &#160; // 判断文件是否存在，不存在则创建 if&#40;file_exists&#40;$this-&#62;file&#41;&#41; &#123; $this-&#62;hits = file_get_contents&#40;$this-&#62;file&#41;; &#125; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://vifix.cn/blog/wp-content/uploads/2009/05/source_php.png" rel="shadowbox[sbpost-922];player=img;" title="source_php"><img class="alignnone size-full wp-image-923" title="source_php" src="http://vifix.cn/blog/wp-content/uploads/2009/05/source_php.png" alt="source_php" width="128" height="128" /></a></p>
<p>嘛，受朋友所托写的，不是什么大不了的东西，贴上来就当给初学者参考吧<br />
只有计数功能，利用session防止重复计数</p>
<p>注意只能运行在PHP5+上</p>
<p>代码见页内：</p>
<p><span id="more-922"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 *  ezcounter
 *  http://vifix.cn
 *  MIT Lisence
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ezcounter<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">const</span> display_only <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> display_and_count <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$hits</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// 构造函数</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ezcounter'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// 存放计数的文件</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">file</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/<span style="color: #006699; font-weight: bold;">$name</span>.txt&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// 判断文件是否存在，不存在则创建</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hits</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hits</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// 获取计数</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> gethits<span style="color: #009900;">&#40;</span><span style="color: #000088;">$flag</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">display_and_count</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$flag</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">display_and_count</span><span style="color: #339933;">:</span>
				<span style="color: #339933;">@</span><span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ezcounter'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hits</span><span style="color: #339933;">++;</span>
					<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hits</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ezcounter'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hits</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">display_only</span><span style="color: #339933;">:</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hits</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// 重定向计数</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> redirect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #339933;">@</span><span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ezcounter'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hits</span><span style="color: #339933;">++;</span>
			<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hits</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ezcounter'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: <span style="color: #006699; font-weight: bold;">$url</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>用法1，只是显示访问计数</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ezcounter.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$counter</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ezcounter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$counter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gethits</span><span style="color: #009900;">&#40;</span>ezcounter<span style="color: #339933;">::</span><span style="color: #004000;">display_and_count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>用法2，转发计数（比如可以用于下载计数）</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//download.php</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ezcounter.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$counter</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ezcounter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'another_file_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$counter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/target'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//view.php</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ezcounter.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$counter</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ezcounter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'another_file_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=&quot;</span>download<span style="color: #339933;">.</span>php<span style="color: #0000ff;">&quot;&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$counter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gethits</span><span style="color: #009900;">&#40;</span>ezcounter<span style="color: #339933;">::</span><span style="color: #004000;">display_only</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://vifix.cn/blog/ezcounter.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>vxtodo</title>
		<link>http://vifix.cn/blog/vxtodo.html</link>
		<comments>http://vifix.cn/blog/vxtodo.html#comments</comments>
		<pubDate>Tue, 12 May 2009 14:39:28 +0000</pubDate>
		<dc:creator>Mac</dc:creator>
				<category><![CDATA[Atelier]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[GAE]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://vifix.cn/blog/?p=895</guid>
		<description><![CDATA[这段时间研究Google App Engine的成果，今天发布。 一个个人TODO-List管理程序，支持邮件提醒。 服务器端是Python，客户端自然还是 HTML + CSS + JS，话说Javascript的代码比Python还多一倍，没jQuery的话代码量应该会更加冗长……不过用Google App Engine来写程序还是挺幸福的。 欢迎各位使用（会有人用么？），以及帮忙测试和报告Bug 在GPL第二版协议下开源。 地址： http://vxtodo.ihfs.net/ http://vxtodo.appspot.com/ 获取源代码前往： http://code.google.com/p/vxtodo/ PS.I: google app engine还无法支持.cn域名，因此只好用这个ihfs.net来进行绑定了…… PS.II: 话说appspot偶尔会被GFW掉，无奈…… PS.III: 于是咱也玩了把云计算了啊～ 更新@2009-05-14: 修正了无法输入\和回车的bug 加入Prism的说明 制作了LOGO 更新@2009-05-15: 修改了数据模型，删除了一些无用的测试数据（没办法的选择，这种键-值数据库无法修改“表结构”，只能清空数据库然后重新添加 更新@2009-05-17: 对状态图标加上了事件，点击可以直接转换状态 将代码导入Google Code，以GPLv2开源 更新@2010-01-17: 解决一个换行的问题]]></description>
			<content:encoded><![CDATA[<p><a rel="attachment wp-att-896" href="http://vifix.cn/blog/vxtodo.html/vxtodo" title="vxtodo"><img class="alignnone size-medium wp-image-896" title="vxtodo" src="http://vifix.cn/blog/wp-content/uploads/2009/05/vxtodo-290x300.png" alt="vxtodo" width="290" height="300" /></a></p>
<p>这段时间研究Google App Engine的成果，今天发布。</p>
<p>一个个人TODO-List管理程序，支持邮件提醒。</p>
<p>服务器端是Python，客户端自然还是 HTML + CSS + JS，话说Javascript的代码比Python还多一倍，没jQuery的话代码量应该会更加冗长……不过用Google App Engine来写程序还是挺幸福的。</p>
<p>欢迎各位使用（会有人用么？），以及帮忙测试和报告Bug</p>
<p>在GPL第二版协议下开源。</p>
<p>地址：<br />
<a href="http://vxtodo.ihfs.net/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/vxtodo.ihfs.net/?referer=');">http://vxtodo.ihfs.net/</a><br />
<a href="http://vxtodo.appspot.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/vxtodo.appspot.com/?referer=');">http://vxtodo.appspot.com/</a></p>
<p>获取源代码前往：<br />
<a href="http://code.google.com/p/vxtodo/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/vxtodo/?referer=');">http://code.google.com/p/vxtodo/</a></p>
<p>PS.I: google app engine还无法支持.cn域名，因此只好用这个ihfs.net来进行绑定了……<br />
PS.II: 话说appspot偶尔会被GFW掉，无奈……<br />
PS.III: 于是咱也玩了把云计算了啊～</p>
<h3>更新@2009-05-14:</h3>
<ol>
<li>修正了无法输入\和回车的bug</li>
<li>加入Prism的说明</li>
<li>制作了LOGO</li>
</ol>
<h3>更新@2009-05-15:</h3>
<ol>
<li>修改了数据模型，删除了一些无用的测试数据（没办法的选择，这种键-值数据库无法修改“表结构”，只能清空数据库然后重新添加</li>
</ol>
<h3>更新@2009-05-17:</h3>
<ol>
<li>对状态图标加上了事件，点击可以直接转换状态</li>
<li>将代码导入Google Code，以GPLv2开源</li>
</ol>
<h3>更新@2010-01-17:</h3>
<ol>
<li>解决一个换行的问题</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://vifix.cn/blog/vxtodo.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>WordPress主题vifix9发布</title>
		<link>http://vifix.cn/blog/vifix9-wordpress-theme-publish.html</link>
		<comments>http://vifix.cn/blog/vifix9-wordpress-theme-publish.html#comments</comments>
		<pubDate>Wed, 15 Apr 2009 09:17:31 +0000</pubDate>
		<dc:creator>Mac</dc:creator>
				<category><![CDATA[Atelier]]></category>
		<category><![CDATA[Website]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://vifix.cn/blog/?p=827</guid>
		<description><![CDATA[最近三天做的东西，生平第一个WordPress的主题，主要是为了和splash页保持一致，顺便化解一下⑨的冲动（不知道我在说啥的无视这句） 效果嘛，见这个Blog目前的状态就知道了。 在创作共用署名-非商业性使用-相同方式共享2.5版协议下发布，感兴趣的可以点击下面的图标链接获取。 右侧的About区域可以自定义使用的gravatar头像和信息（如果没有设定则使用用户列表中的第一位的电子邮件来生成头像）。上面的“⑨”位置的超级连接也可以修改（自带Options页面）。另外，用了一些WordPress 2.7才有的函数，所以在2.7之前的版本上是无法使用的。 目前仍然有诸多问题（好像每次发布点啥都有问题……） 在添加自定义的widget添加上去的不美观，写CSS写到累了，还是以后再改了 orz 一些文本调用了WordPress的本地化文件，而一些文本则没有调用，在中文的WordPress上，会看到自带的widget中英文标题共同显示的情况…… updated @ 2009-04-16 0.2版本发布，修改了链接的风格，解决一个HTML上的Bug]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-829" title="vifix9-wp-theme-screenshot" src="http://vifix.cn/blog/wp-content/uploads/2009/04/vifix9-wp-theme-screenshot.jpg" alt="vifix9-wp-theme-screenshot" width="250" height="200" /></p>
<p>最近三天做的东西，生平第一个WordPress的主题，主要是为了和<a href="http://vifix.cn" target="_blank">splash页</a>保持一致，顺便化解一下⑨的冲动（不知道我在说啥的无视这句）</p>
<p>效果嘛，见这个Blog目前的状态就知道了。</p>
<p>在<a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/creativecommons.org/licenses/by-nc-sa/2.5/cn/?referer=');">创作共用署名-非商业性使用-相同方式共享2.5版协议</a>下发布，感兴趣的可以点击下面的图标链接获取。</p>
<p><a href="http://vifix.cn/blog/wp-content/uploads/2009/04/vifix9.zip"><img src="http://vifix.cn/blog/wp-includes/images/crystal/archive.png" alt="vifix9.zip" /></a></p>
<p>右侧的About区域可以自定义使用的gravatar头像和信息（如果没有设定则使用用户列表中的第一位的电子邮件来生成头像）。上面的“⑨”位置的超级连接也可以修改（自带Options页面）。另外，用了一些WordPress 2.7才有的函数，所以在2.7之前的版本上是无法使用的。</p>
<p>目前仍然有诸多问题（好像每次发布点啥都有问题……）</p>
<ul>
<li>在添加自定义的widget添加上去的不美观，写CSS写到累了，还是以后再改了 orz</li>
<li>一些文本调用了WordPress的本地化文件，而一些文本则没有调用，在中文的WordPress上，会看到自带的widget中英文标题共同显示的情况……</li>
</ul>
<h3>updated @ 2009-04-16</h3>
<p>0.2版本发布，修改了链接的风格，解决一个HTML上的Bug</p>
]]></content:encoded>
			<wfw:commentRss>http://vifix.cn/blog/vifix9-wordpress-theme-publish.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>首页更新</title>
		<link>http://vifix.cn/blog/vifix-cn-homepage-updated.html</link>
		<comments>http://vifix.cn/blog/vifix-cn-homepage-updated.html#comments</comments>
		<pubDate>Sun, 12 Apr 2009 11:42:55 +0000</pubDate>
		<dc:creator>Mac</dc:creator>
				<category><![CDATA[Atelier]]></category>
		<category><![CDATA[Website]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://vifix.cn/blog/?p=825</guid>
		<description><![CDATA[觉得先前的首页在载入效率上很有问题，于是干脆一鼓作气重新做了一个，总共消耗大概16个小时。并且加入了一些细节和效果和内容（主要是一些个人的作品）。嘛，今年过后也得找工作了，就当广告先做起来吧～ 访问：http://vifix.cn 眼下似乎还有一些问题，慢慢进行调整了。 滚动和音效分别使用了这两个jQuery插件：jQuery.jScrollPane, jQuery.flashSound PS: 搞这个东西时项目目录命名为vifix9（因为是09年），真有改成⑨的冲动……]]></description>
			<content:encoded><![CDATA[<p><a href="http://vifix.cn/blog/wp-content/uploads/2009/04/vifix9.jpg" rel="shadowbox[sbpost-825];player=img;" title="vifix9"><img class="alignnone size-medium wp-image-824" title="vifix9" src="http://vifix.cn/blog/wp-content/uploads/2009/04/vifix9-300x165.jpg" alt="vifix9" width="300" height="165" /></a></p>
<p>觉得先前的首页在载入效率上很有问题，于是干脆一鼓作气重新做了一个，总共消耗大概16个小时。并且加入了一些细节和效果和内容（主要是一些个人的作品）。嘛，今年过后也得找工作了，就当广告先做起来吧～</p>
<p>访问：<a href="http://vifix.cn">http://vifix.cn</a></p>
<p>眼下似乎还有一些问题，慢慢进行调整了。</p>
<p>滚动和音效分别使用了这两个jQuery插件：<a href="http://www.kelvinluck.com/assets/jquery/jScrollPane/jScrollPane.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.kelvinluck.com/assets/jquery/jScrollPane/jScrollPane.html?referer=');">jQuery.jScrollPane</a>, <a href="http://www.bootleq.com/item/flashSound/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.bootleq.com/item/flashSound/?referer=');">jQuery.flashSound</a></p>
<p>PS: 搞这个东西时项目目录命名为vifix9（因为是09年），真有改成⑨的冲动……</p>
]]></content:encoded>
			<wfw:commentRss>http://vifix.cn/blog/vifix-cn-homepage-updated.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Java中的支持重试，有限任务数量线程池</title>
		<link>http://vifix.cn/blog/java-limited-task-amount-threads-pool.html</link>
		<comments>http://vifix.cn/blog/java-limited-task-amount-threads-pool.html#comments</comments>
		<pubDate>Tue, 24 Mar 2009 09:18:47 +0000</pubDate>
		<dc:creator>Mac</dc:creator>
				<category><![CDATA[Atelier]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://vifix.cn/blog/?p=788</guid>
		<description><![CDATA[昨天学校网络没有续费没法上网，晚上找事情干，就翻着O&#8217;Reilly的《Java线程》（第三版）看了一些内容然后写的实验性质的代码，主要是对于Konachan的线程池代码很不满意而写的。 这些代码主要包括： 三个线程复用的线程池（利用ThreadPoolExecutor） 通过判断线程池现有的活动线程数量限制ThreadPoolExecutor执行新任务 如果执行出错，可以自动重试（这里的“任务”有80%的成功率） 利用Hashtable&#60;Integer, String&#62;来记录“任务”的运行状态，如果不在Hashtable中，表示任务已经结束 每个“任务”耗时0到10000毫秒（利用Thread.sleep模拟） 然而这个实现也让人觉得不够优雅，也许自己实现一个RejectedExecutionHandler接口的类，然后绑定为ThreadPoolExecutor的弹出策略才是王道吧。另外，觉得应该还需要自己还要再写一个队列。 完整的代码（Eclipse工程在文末）： Main: package cn.vifix.concurrentLab; import java.util.Hashtable; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; &#160; public class ThreadPoolDemo &#123; public static Hashtable&#60;Integer,String&#62; jobs; &#160; public static void main&#40;String&#91;&#93; args&#41; &#123; new ThreadPoolDemo&#40;&#41;; &#125; &#160; public ThreadPoolDemo&#40;&#41; &#123; jobs = new Hashtable&#60;Integer, String&#62;&#40;&#41;; int taskCount = 30; for &#40;int [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://vifix.cn/blog/wp-content/uploads/2009/03/threadpooldemo_output.png" rel="shadowbox[sbpost-788];player=img;" title="threadpooldemo_output"><img src="http://vifix.cn/blog/wp-content/uploads/2009/03/threadpooldemo_output-300x123.png" alt="threadpooldemo_output" title="threadpooldemo_output" width="300" height="123" class="alignnone size-medium wp-image-789" /></a></p>
<p>昨天学校网络没有续费没法上网，晚上找事情干，就翻着O&#8217;Reilly的《Java线程》（第三版）看了一些内容然后写的实验性质的代码，主要是对于<a href="http://vifix.cn/blog/konachan.html">Konachan</a>的线程池代码很不满意而写的。</p>
<p>这些代码主要包括：</p>
<ol>
<li>三个线程复用的线程池（利用ThreadPoolExecutor）</li>
<li>通过判断线程池现有的活动线程数量限制ThreadPoolExecutor执行新任务</li>
<li>如果执行出错，可以自动重试（这里的“任务”有80%的成功率）</li>
<li>利用Hashtable&lt;Integer, String&gt;来记录“任务”的运行状态，如果不在Hashtable中，表示任务已经结束</li>
<li>每个“任务”耗时0到10000毫秒（利用Thread.sleep模拟）</li>
</ol>
<p>然而这个实现也让人觉得不够优雅，也许自己实现一个RejectedExecutionHandler接口的类，然后绑定为ThreadPoolExecutor的弹出策略才是王道吧。另外，觉得应该还需要自己还要再写一个队列。</p>
<p>完整的代码（Eclipse工程在文末）：</p>
<p><span id="more-788"></span></p>
<p><strong>Main:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">cn.vifix.concurrentLab</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Hashtable</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.concurrent.SynchronousQueue</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.concurrent.ThreadPoolExecutor</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.concurrent.TimeUnit</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ThreadPoolDemo
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Hashtable<span style="color: #339933;">&lt;</span>Integer,String<span style="color: #339933;">&gt;</span> jobs<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">new</span> ThreadPoolDemo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ThreadPoolDemo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		jobs <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Hashtable<span style="color: #339933;">&lt;</span>Integer, String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> taskCount <span style="color: #339933;">=</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>taskCount<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			jobs.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>i, <span style="color: #0000ff;">&quot;todo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		SynchronousQueue<span style="color: #339933;">&lt;</span>Runnable<span style="color: #339933;">&gt;</span> queue <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SynchronousQueue<span style="color: #339933;">&lt;</span>Runnable<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		ThreadPoolExecutor exec <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ThreadPoolExecutor<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">20</span>, TimeUnit.<span style="color: #006633;">SECONDS</span>, queue, <span style="color: #000000; font-weight: bold;">new</span> ThreadPoolExecutor.<span style="color: #006633;">DiscardPolicy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>jobs.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>exec.<span style="color: #006633;">getActiveCount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thread count == 3; Skip this loop...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> taskCount <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>jobs.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>jobs.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;todo&quot;</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						jobs.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>i, <span style="color: #0000ff;">&quot;doing&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						exec.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ThreadPoolDemoWorker<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">synchronized</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">out</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>jobs.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Task Left:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; List:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>jobs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;All done.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Worker:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">cn.vifix.concurrentLab</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ThreadPoolDemoWorker <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Runnable</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> idx<span style="color: #339933;">;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">new</span> ThreadPoolDemoJob<span style="color: #009900;">&#40;</span>idx<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">process</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ThreadPoolDemoWorker<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		idx <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Task:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">cn.vifix.concurrentLab</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Random</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ThreadPoolDemoTask
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> idx<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Random</span> random<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ThreadPoolDemoTask<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		idx <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span>
		random <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> process<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span>random.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InterruptedException</span> ex<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">doTask</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> doTask<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>random.<span style="color: #006633;">nextFloat</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0.8</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			ThreadPoolDemo.<span style="color: #006633;">jobs</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>idx, <span style="color: #0000ff;">&quot;todo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">synchronized</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">out</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Task &quot;</span> <span style="color: #339933;">+</span> idx <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; failed.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Task &quot;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>idx<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; failed, retry.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">synchronized</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">out</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Task &quot;</span> <span style="color: #339933;">+</span> idx <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; done.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			ThreadPoolDemo.<span style="color: #006633;">jobs</span>.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>idx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><a href='http://vifix.cn/blog/wp-content/uploads/2009/03/threadpooldemo.zip'>Eclipse工程</a>，欢迎共同研究！</p>
]]></content:encoded>
			<wfw:commentRss>http://vifix.cn/blog/java-limited-task-amount-threads-pool.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

