java¶ÁдËøʵÏÖ»úÖÆ
package thread.lock;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
* @file_name ReadAndWriteLockDemo.java
* @description ¶ÁдËøDEMO
* @author ÕÅÃ÷ÁÁ
* @date 2009.09.27
*/
public class ReadAndWriteLockDemo {
ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();
// ¶ÁËø
Lock rLock = rwLock.readLock();
// дËø
Lock wLock = rwLock.writeLock();
// »õ¼Ü
List<String> stock = new ArrayList<String>();
//»¥³âËø
ReentrantLock lock = new ReentrantLock();
/**
* ÉÌÆ·ÂòÂô
* <br>
* µ±ÉÌÆ·ÊýÁ¿Ð¡ÓÚ1ʱ£¬ÊͷŶÁËø²¢»ñȡдËø Éú²úÉÌÆ·ºó£¬
* <br>
* Ëø½µ¼¶ÔÚдËø±£»¤ÏÂÖØлñÈ¡¶ÁËø²¢Ïû·ÑÉÌÆ·
*/
public void sell() {
// lock.lock();
try {
rLock.lock();
if (stock.size() <= 0) {
rLock.unlock();
wLock.lock();
manufacture();
rLock.lock();
wLock.unlock();
}
consume();
rLock.unlock();
} finally {
// lock.unlock();
}
}
/**
* Éú²úÉÌÆ·
*/
private void manufacture() {
stock.add("product");
}
/**
* Ïû·ÑÉÌÆ·
*/
private void consume() {
System.err.println(stock.remove(0));
}
public static void main(String[] args) {
final ReadAndWriteLockDemo rwDemo = new ReadAndWriteLockDemo();
rwDemo.sell();
// Thread t1 = new Thread("threa--1") {
// public void run() {
// rwDemo.sell(
Ïà¹ØÎĵµ£º
½ñÌìÓöµ½ÁËÕâ¸öÎÊÌâ ÁËºÇºÇ ½â¾öÁ˸ø´ó¼Ò·ÖÏíÏÈ£¬java.lang.OutOfMemoryError: Java heap space ÒýÆðÁËÎÒÉÏ´«³ö´í¡£ÎÒ½â¾ö°ì·¨¾ÍÊÇ¿´ÄãʹÓõÄtomcat·þÎñÆ÷°æ±¾ÊÇʲôÑùµÄ£¬Èç¹ûÄãµÄtomcat/binϱßÓÐtomcatw.exe ¾Í·½±ãÁË£¬Ö±½Ó¿ÉÊÓ»¯²Ù×÷ŶÏÂÏÂͼ
ÆäÖÐÉèÖóõʼÄÚ´æ³ØºÍ×î´óÄÚ´æ³Ø£¬ÉèÖÃÔÔòÊǸù¾ÝÄãµÄÎïÀíÄÚ´æÀ´¶¨¡£
Èç¹û ......
¿ÉÒÔ°ÑÆÕͨµÄJava³ÌÐò×ö³ÉÕæÕýµÄexe,Ò²¾ÍÊǵ¥Ò»¸öexe¾Í¿ÉÒÔÔÚûÓа²×°JVMµÄ»úÆ÷ÉÏÔËÐС£ÕâÑùµÄ¹¤¾ß³£¼ûµÄÓÐJETºÍgcj.Ç°ÕßÊÇÊշѵģ¬¶øÇÒ×ö³öÀ´µÄexe»¹ÊÇÐèÒªÒ»¶Ñdll¡£ÍƼöʹÓÃgcj.ËûÓÐwindowsºÍLinux°æ£¬Ö±½ÓÏÂÔØzip°ü£¬²»ÐèÒª°²×°£¬ÀïÃæÓв»ÉÙÀý×Ó£¬Ò»Ð©buildµÄÅú´¦ÀíÎļþ¡£´ÓÔÀíÀ´Ëµgcj×Ô¼ºÊµÏÖÁËJVM¹æ·¶£¬Ò²¾ÍÊÇÄ ......
ºÜ¶àÍøÓÑÎÊÎÒѧϰJavaÓÐûÓÐʲô½Ý¾¶,ÎÒ˵“ÎÞËû£¬Î¨ÊÖÊì¶û”¡£µ«ÊÇÎÒÈ´ºÜÔ¸Ò⽫×Ô¼ºÑ§Ï°µÄһЩ¾Ñéд³öÀ´£¬ÒÔ±ãºóÀ´ÕßÉÙ×ßÍä·,°ïÖú±ðÈËÊÇ×î´óµÄ¿ìÀÖÂ
ÒªÏëѧºÃJava£¬Ê×ÏÈÒªÖªµÀJavaµÄ´óÖ·ÖÀà¡£ÎÒÃÇÖªµÀ£¬×Ô´ÓSunÍƳöJavaÒÔÀ´£¬¾ÍÁ¦Í¼Ê¹Ö®ÎÞËù²»°ü£¬ËùÒÔJava·¢Õ¹µ½ÏÖÔÚ£¬°´Ó¦ÓÃÀ´·ÖÖ÷Òª·ÖΪÈý´ó¿é£ºJ2SE,J2 ......
#(¶Á×ö "C sharp")ÊÇ΢Èí¹«Ë¾ÔÚÈ¥ÄêÁùÔ·¢²¼µÄÒ»ÖÖеıà³ÌÓïÑÔ,²¢¶¨ÓÚÔÚ΢ÈíÖ°Òµ¿ª·¢ÕßÂÛ̳(PDC)ÉϵÇ̨ÁÁÏà.C#ÊÇ΢Èí¹«Ë¾Ñо¿Ô±Anders HejlsbergµÄ×îгɹû.C#¿´ÆðÀ´ÓëJavaÓÐמªÈ˵ÄÏàËÆ;Ëü°üÀ¨ÁËÖîÈçµ¥Ò»¼Ì³Ð,½çÃæ,ÓëJava¼¸ºõͬÑùµÄÓï·¨,ºÍ±àÒë³ÉÖмä´úÂëÔÙÔËÐеĹý³Ì.µ«ÊÇC#ÓëJavaÓÐ×ÅÃ÷ÏԵIJ»Í¬,Ëü½è¼øÁËDelphiµÄÒ»¸ ......
ÔÚ¡¶JDBC Driver For SQL2000/2005/2008
¡·Ò»ÎÄÖУ¬ÑûÔ½éÉÜÁËÈçºÎÏÂÔز¢Ê¹ÓÃjdbcÁ¬½ÓSQL Server,
½ñÌìÓÐÈËÎÊÆð£¬ÈçºÎÒÔwindows¼¯³É·½Ê½Á¬½ÓSQL Server,Õâ¸öÒÔÇ°ÕæûÊÔ¹ý¡£
ÓÚÊÇ£¬´ò¿ªnetBeans²âÊÔÁËһϣ¬´úÂëÈçÏ£º
/*
* To change this template, choose Tools | Templates
* and open the template in the edit ......