﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-yuyee</title><link>http://www.blogjava.net/yuyee/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 12 Apr 2026 01:18:10 GMT</lastBuildDate><pubDate>Sun, 12 Apr 2026 01:18:10 GMT</pubDate><ttl>60</ttl><item><title>PriorityBlockingQueue</title><link>http://www.blogjava.net/yuyee/archive/2010/11/01/336701.html</link><dc:creator>羔羊</dc:creator><author>羔羊</author><pubDate>Mon, 01 Nov 2010 08:33:00 GMT</pubDate><guid>http://www.blogjava.net/yuyee/archive/2010/11/01/336701.html</guid><wfw:comment>http://www.blogjava.net/yuyee/comments/336701.html</wfw:comment><comments>http://www.blogjava.net/yuyee/archive/2010/11/01/336701.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yuyee/comments/commentRss/336701.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yuyee/services/trackbacks/336701.html</trackback:ping><description><![CDATA[PriorityBlockingQueue：一个无界的<a title="java.util.concurrent 中的接口" href="">阻塞队列</a>，它使用与类 <a title="java.util 中的类" href=""><code>PriorityQueue</code></a>
相同的顺序规则，并且提供了阻塞检索的操作。虽然此队列逻辑上是无界的，但是由于资源被耗尽，所以试图执行添加操作可能会失败（导致
<tt>OutOfMemoryError</tt>）。此类不允许使用 <tt>null</tt>
元素。依赖自然顺序的优先级队列也不允许插入不可比较的对象（因为这样做会抛出 <tt>ClassCastException</tt>）。
<p>&nbsp;<code><strong><a href="">PriorityBlockingQueue</a></strong>()</code> </p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用默认的初始容量 (11) 创建一个
<tt>PriorityBlockingQueue</tt>，并根据元素的自然顺序排序其元素（使用
<tt>Comparable</tt>）。
<code><strong><a href="">PriorityBlockingQueue</a></strong>(<a title="java.util 中的接口" href="">Collection</a>&lt;? extends <a title="PriorityBlockingQueue 中的类型参数" href="">E</a>&gt;&nbsp;c)</code>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;创建一个包含指定集合中元素的 <tt>PriorityBlockingQueue</tt>。
<code><strong><a href="">PriorityBlockingQueue</a></strong>(int&nbsp;initialCapacity)</code>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使用指定的初始容量创建一个 <tt>PriorityBlockingQueue</tt>，并根据元素的自然顺序排序其元素（使用
<tt>Comparable</tt>）。
<code><strong><a href="">PriorityBlockingQueue</a></strong>(int&nbsp;initialCapacity,
<a title="java.util 中的接口" href="">Comparator</a>&lt;? super <a title="PriorityBlockingQueue 中的类型参数" href="">E</a>&gt;&nbsp;comparator)</code>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使用指定的初始容量创建一个 <tt>PriorityBlockingQueue</tt>，并根据指定的比较器排序其元素。
<div><br />
</div>
<div>此类每次offer元素，都会有一个fixup操作，也就是排序，如果没有构造的时候传入自己实现的比较器，就采用自然排序，否则采用比较器规则，进行二分查找，比较，保持列头是比较器希望的那个最大或则最小元素。</div>
<div>
<div>&nbsp;private void fixUp(int k) {</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (comparator == null) {</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while (k &gt; 1) {</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int j = k &gt;&gt; 1;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (((Comparable&lt;E&gt;)queue[j]).compareTo((E)queue[k]) &lt;= 0)</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Object tmp = queue[j]; &nbsp;queue[j] = queue[k]; queue[k] = tmp;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;k = j;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;} else {</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while (k &gt; 1) {</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int j = k &gt;&gt;&gt; 1;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (comparator.compare((E)queue[j], (E)queue[k]) &lt;= 0)</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Object tmp = queue[j]; &nbsp;queue[j] = queue[k]; queue[k] = tmp;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;k = j;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div>
<div>&nbsp;&nbsp; &nbsp;}</div>
</div>
<img src ="http://www.blogjava.net/yuyee/aggbug/336701.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yuyee/" target="_blank">羔羊</a> 2010-11-01 16:33 <a href="http://www.blogjava.net/yuyee/archive/2010/11/01/336701.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OSGI小记</title><link>http://www.blogjava.net/yuyee/archive/2010/10/26/336202.html</link><dc:creator>羔羊</dc:creator><author>羔羊</author><pubDate>Tue, 26 Oct 2010 09:28:00 GMT</pubDate><guid>http://www.blogjava.net/yuyee/archive/2010/10/26/336202.html</guid><description><![CDATA[前几个人因为项目中考虑使用OSGI来开发，因此和同事调研了大概1个多月，当时没做记录，现在来弥补下
<div>OSIG，一个构件模块化，动态化系统的标准，众多应用服务器实现微核采用的技术，如weblogic,glassfish,最出名的是equinox,eclipse核心。</div>
<div>在OSGI环境中，体现模块化，动态化，</div>
<div>模块化：模块之间独立，部首其他模块影响。</div>
<div>其他模块只能访问该模块对外提供的服务</div>
<div>模块具备独立的生命周期，如启动，停止，更新</div>
<div>动态化：</div>
<div>对于模块的增加，修改，删除，不需要做 额外的处理。</div>
<div>OSGI中，每个模块就是在物理上就是一个bundle,一个JAR包，是OSGI部署的最小单位，需要在每个JAR包的MANIFEST.MF中给这个bundle标识，象bundle-name,Bundle-SymbolicName,Bundle-ClassPath,Bundle-Activator;</div>
<div>OSGI中bundle的隔离是通过java ClassLoader隔离性来完成的，JAVA中每个classloader空间都是隔离的，默认的classloader有bootStrap ClassLoader(jre/lib,jre/classes) extension classloader(jre/lib/ext),system classloader(-classpath),一般osgi框架还实现自己的应用类加载器。</div>
<div>bundle隔离机制实现：每个bundle都有一个独立的classloader,通过bundle-classpath指定JAR路径</div>
<div>java中通过双亲委托来加载类，寻找类首先是从parent classloader中寻找，如果找不到才在当前的clasloader中寻找</div>
<div>bundle类加载过程：</div>
<div>java.*开头的类委派给parent classloader加载；</div>
<div>bootdelegationcan参数中配置的也委派给parent classloader加载，parent classloader找不到则继续下面的操作；</div>
<div>是否在import-Package中，在则委派给导出他的bundle的classloader 加载，不在则继续下面</div>
<div>是否在require-bundle中，在则委派给相应的bundleloader加载，不在继续下面的</div>
<div>是否在自己的bundle-classpath 中，不在则继续下面的</div>
<div>是否在fragmentsbundle的classpath中寻找，不在则继续下面的(<span style="font-family: arial, nsimsun, sans-serif; font-size: 12px; "><span style="font-family: arial, nsimsun, sans-serif; font-size: 12px; ">&nbsp;</span></span><span style="font-family: arial, nsimsun, sans-serif; font-size: 12px; ">在 OSGi 框架中提供了一种称为 fragment 的特殊 bundle。在装载的过程中，这类 fragment 是被附加到被称为&#8220;宿主&#8221;的 bundle 上，最后作为一个整体 bundle 运行于 OSGi 环境中。最为典型的 fragment 应用场景是多语言包发布，将包含多语言包的 bundle 作为主体程序 bundle 的 fragment，这样可以将多语言包和主体 bundle 作为两个独立的部分来发布，但在运行时它们又是一个整体。</span>)</div>
<div>是否在export-package中，不在继续下面的</div>
<div>是否在dynamicimport-package中，在则加载，不在则抛classNotfoundexception</div>
<div>通过MANIFEST.MF定义import-package等，当要注意，最好定义包的版本 如：Import-Package: org.eclipse.osgi.framework.console;version="1.0.0",</div>
<div>&nbsp;org.osgi.framework;version="1.3.0"</div>
<div>Import-Package寻找机制：</div>
<div>resolved的优先未resolved</div>
<div>版本高的优先版本低的，如果版本一样，则比较bundle id,小的优先，也就是先安装的bundle优先</div>
<div><br />
</div>
<div><br />
</div>
<div><br />
</div>
<img src ="http://www.blogjava.net/yuyee/aggbug/336202.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yuyee/" target="_blank">羔羊</a> 2010-10-26 17:28 <a href="http://www.blogjava.net/yuyee/archive/2010/10/26/336202.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>