當(dāng)沒(méi)有使用JIT或Hotspot虛擬機(jī)時(shí),盡量使用0值作為終結(jié)條件的比較元素,以提高循環(huán)語(yǔ)句的性能。
零值比較
今天看了一博文介紹Java線程安全方面的,好像和之前看過(guò)的一本書Java Concurrency in Practice中的內(nèi)容差不多。努力學(xué)習(xí)消化之。
注意:
那么大家肯定會(huì)想,在方法中加同步關(guān)鍵字和在方法里面分解出耗時(shí)且不影響類狀態(tài)的改變的同步代碼塊,這兩個(gè)解決方案如何選擇呢?
那么必須要編程者清晰的知道類中的變量和競(jìng)爭(zhēng)條件。所以編程者要切記在方法中添加關(guān)鍵字,雖然簡(jiǎn)單但是會(huì)影響并發(fā)性能,特別是在方法里面含有耗時(shí)的操作,如:I/O,網(wǎng)絡(luò)連接、等等。
Use the Apache Ant tool to create these files. Apache Ant is a Java-based build tool that enables you to generate XML-based configurations files as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<project default="build">
<dirname property="basedir" file="${ant.file}"/>
<property name="beanname" value="SimpleBean"/>
<property name="jarfile" value="${basedir}/${beanname}.jar"/>
<target name="build" depends="compile">
<jar destfile="${jarfile}" basedir="${basedir}" includes="*.class">
<manifest>
<section name="${beanname}.class">
<attribute name="Java-Bean" value="true"/>
</section>
</manifest>
</jar>
</target>
<target name="compile">
<javac destdir="${basedir}">
<src location="${basedir}"/>
</javac>
</target>
<target name="clean">
<delete file="${jarfile}">
<fileset dir="${basedir}" includes="*.class"/>
</delete>
</target>
</project>