java ×Ô¼ºÊµÏÖ ReadWriteLock £¨Ò»£©
¶àÏ̶߳Áдͬһ¸ö¶ÔÏóµÄÊý¾ÝÊǺÜÆÕ±éµÄ£¬Í¨³££¬Òª±ÜÃâ¶Áд³åÍ»£¬±ØÐë±£Ö¤ÈκÎʱºò½öÓÐÒ»¸öÏß³ÌÔÚдÈ룬ÓÐÏß³ÌÕýÔÚ¶ÁÈ¡µÄʱºò£¬Ð´Èë²Ù×÷¾Í±ØÐëµÈ´ý¡£¼òµ¥Ëµ£¬¾ÍÊÇÒª±ÜÃâ“д-д”³åÍ»ºÍ“¶Á-д”³åÍ»¡£µ«ÊÇͬʱ¶ÁÊÇÔÊÐíµÄ£¬ÒòΪ“¶Á-¶Á”²»³åÍ»£¬¶øÇҺܰ²È«¡£
ҪʵÏÖÒÔÉϵÄReadWriteLock£¬¼òµ¥µÄʹÓÃsynchronized¾Í²»ÐУ¬ÎÒÃDZØÐë×Ô¼ºÉè¼ÆÒ»¸öReadWriteLockÀ࣬ÔÚ¶Á֮ǰ£¬±ØÐëÏÈ»ñµÃ“¶ÁËø”£¬Ð´Ö®Ç°£¬±ØÐëÏÈ»ñµÃ“дËø”¡£¾ÙÀý˵Ã÷£º
DataHandler¶ÔÏó±£´æÁËÒ»¸ö¿É¶ÁдµÄchar[]Êý×飺
package com.crackj2ee.thread;
public class DataHandler {
// store
data:
private
char[] buffer = "AAAAAAAAAA".toCharArray();
private
char[] doRead() {
char[] ret = new char[buffer.length];
for(int i=0; i<buffer.length; i++) {
ret[i] = buffer[i];
sleep(3);
}
return ret;
}
private void
doWrite(char[] data) {
if(data!=null) {
buffer = new char[data.length];
for(int i=0; i<buffer.length; i++) {
buffer[i] = data[i];
sleep(10);
}
}
}
private void
sleep(int ms) {
try {
&nb
Ïà¹ØÎĵµ£º
½ñÌìÎÒÔÚ×ö·É»ú¡£ÎªÊ²Ã´ËµÎÒÔÚ×ö·É»úÄØ£¡ÒòΪÕâÊÇÎÒ½ø´«ÖDz¥¿ÍÒÔÀ´£¬¸öÈ˸оõ·Ç³£ÖØÒªµÄÒ»ÌÿΣ¬µ«ÊÇÎÒ²»ÄÜÒ»ÏÂ×Ó¼ÇסËùËùÓеĶ«Î÷£¬×òÌìÍíÉÏ£¬¿´ÊÓƵ¿´µ½ÍíÉÏÈýµã£¬½ñÌìÉϿκÜÏ뼯ÖÐ×¢ÒâÁ¦£¬µ«ÊÇ×îÖÕ»¹ÊÇÈ̲»×¡´òÁËî§Ë¯£¬µ«½ñÌìµÄµÄ¿Î¸øÎҵĸоõÊǷdz£¾ßÓÐÁ¬¹áÐÔ£¬Ç°ÃæµÄ¿ÎÈç¹ûÌýµÃ²»ÊǺÜÇ ......
SQL×¢ÈëÊÇ×î³£¼ûµÄ¹¥»÷·½Ê½Ö®Ò»,Ëü²»ÊÇÀûÓòÙ×÷ϵͳ»òÆäËüϵͳµÄ©¶´À´ÊµÏÖ¹¥»÷µÄ,¶øÊdzÌÐòÔ±ÒòΪûÓÐ×öºÃÅжÏ,±»²»·¨
Óû§×êÁËSQLµÄ¿Õ×Ó,ÏÂÃæÎÒÃÇÏÈÀ´¿´ÏÂʲôÊÇSQL×¢Èë:
±ÈÈçÔÚÒ»¸öµÇ½½çÃæ,ÒªÇóÓû§ÊäÈëÓû§ÃûºÍÃÜÂë:
& ......
¼øÓÚÍøÉ϶ÔJavaµÄ¶ÑÕ»Çø·Ö£¬ÖÚ˵·×ç¡£¬ÓеİÑC++µÄ¶ÑÕ»Ò²»ì½øÀ´£¬ÓеÄûÓзÖÇåStack£¬HeapµÄÖÐÎÄ·Ò룬¸ãµÃÎÒ°ÑStackµ±×÷¶Ñ£¬Heapµ±×÷Õ»£¬»ìÂÒÁË£¡×òÌì²Î¼ÓÒ»ÍâÆóµÄ±ÊÊÔ£¬Ñ¡ÔñÓ¢ÎÄ´ð°¸Ê±£¬Ñ¡´íÁË£¬ÖªµÀ´ð°¸ÊǶѣ¬È´Ñ¡ÔñÁËStack£¡½ñÌ죬¾ö¶¨°ÑÁ½ÕßÇø·ÖÇå³þ£¡
&nbs ......
µÚÒ»´Î·¢,Ñ¡¸öÄѶÈÊʵ±ÖеÄ:ÎÒ¸Õ±Ïҵʱ²Î¼ÓµÄÒ»´Î±ÊÊÔ.
Ìâ:¶ÔÈÎÒâÊäÈëÈëµÄÒ»¸ö×Ö·û´®£¬°ÑÊý×Ö´ÓСµ½´óÅÅÁУ¬×ÖĸÄæÐòÅÅÁÐ,²¢ÇÒÊäÈëºó×ÖĸÓëÊý¾Ý½»ÌæÅÅÁС£
Èç:"5s3fa72cs4z134556sdd"Ö´ÐкóΪ"z1s2s3s3f4d4d5c5a56".
´ó¼Ò¿ÉÒÔÊÔÒ»ÏÂ,¹²Í¬Ñ§Ï°Âð?ÏÂÃæÊÇÎÒµ±³¡×öµÄ,Ïëµ½ÄÄдµ½ÄÄ,Ëã·¨¿Ï¶¨²»ÓÅ,½ö¹©²Î¿¼.
import java.util ......