方偉的博客
          j2ee技術、網絡、web等,同名的人真多,我的QQ是20025404
          posts - 21,comments - 14,trackbacks - 0
               摘要: 對于volatile修飾的變量,jvm虛擬機只是保證從主內存加載到線程工作內存的值是最新的
          例如假如線程1,線程2 在進行read,load 操作中,發現主內存中count的值都是5,那么都會加載這個最新的值
          在線程1堆count進行修改之后,會write到主內存中,主內存中的count變量就會變為6
          線程2由于已經進行read,load操作,在進行運算之后,也會更新主內存count的變量值為6
          導致兩個線程及時用volatile關鍵字修改之后,還是會存在并發的情況。
            閱讀全文
          posted @ 2013-05-30 15:26 方偉的博客 閱讀(319) | 評論 (0)編輯 收藏
          /* *Author:tyfun *DateTime:2002.12.19 *Package:com.westarsoft.function */ package com.westarsoft.function; public class HtmlFilter { /*USE: *String escapeHTMLTags( String input , boolean htmlFlag ) */ public static String escapeHTMLTags( String input , boolean htmlFlag ) { if( input == null || input.length() == 0 || htmlFlag ) { return input; } StringBuffer buf = new StringBuffer(input.length()+6); char ch = '' ''; for( int i=0; i'' ) { buf.append( ">" ); } else { buf.append( ch ); } } return buf.toString(); } /*USE: *String replace( String line, String oldString, String newString ) */ public static String replace( String line, String oldString, String newString ) { int i=0; if ( ( line == null || oldString == null ) ) { return null; } if ( ( i=line.indexOf( oldString, i ) ) >= 0 ) { int oLength = oldString.length(); int nLength = newString.length(); StringBuffer buf = new StringBuffer(); buf.append(line.substring(0,i)).append(newString); i += oLength; int j = i; while( (i=line.indexOf(oldString,i)) > 0 ) { buf.append(line.substring(j,i)).append(newString); i += oLength; j = i; } buf.append(line.substring(j)); return buf.toString(); } return line; } /*USE: *String replaceIgnoreCase( String line, String oldString, String newString ) */ public static String replaceIgnoreCase( String line, String oldString, String newString ) { if (line == null) { return null; } String lcLine = line.toLowerCase(); String lcOldString = oldString.toLowerCase(); int i=0; if ( ( i=lcLine.indexOf( lcOldString, i ) ) >= 0 ) { char [] line2 = line.toCharArray(); char [] newString2 = newString.toCharArray(); int oLength = oldString.length(); StringBuffer buf = new StringBuffer(line2.length); buf.append(line2, 0, i).append(newString2); i += oLength; int j = i; while( ( i=lcLine.indexOf( lcOldString, i ) ) > 0 ) { buf.append(line2, j, i-j).append(newString2); i += oLength; j = i; } buf.append(line2, j, line2.length - j); return buf.toString(); } return line; } /*USE: *String convertUBB( String input ) */ public static String convertUBB ( String input ) { if( input == null || input.length() == 0 ) { return input; } else { input = replaceIgnoreCase( input , "<" ,"<" ) ; input = replaceIgnoreCase( input , "<%" ,"<%" ) ; input = replaceIgnoreCase( input , "%>" ,"%>" ) ; input = replaceIgnoreCase( input , ">" ,">" ) ; input = replaceIgnoreCase( input , "" ,"" ) ; input = replaceIgnoreCase( input , "" ,"" ) ; input = replaceIgnoreCase( input , "" ,"" ) ; input = replaceIgnoreCase( input , "" ,"" ) ; input = replaceIgnoreCase( input , "" ,"" ) ; input = replaceIgnoreCase( input , "" ,"" ) ; input = replaceIgnoreCase( input , "[red]" ,"" ) ; input = replaceIgnoreCase( input , "[/red]" ,"" ) ; input = replaceIgnoreCase( input , " " ,"
            " ) ; input = replaceIgnoreCase( input , " " ,"
          " ) ; input = replaceIgnoreCase( input , " " ,"
        1. " ) ; input = replaceIgnoreCase( input , "" ,"
        2. " ) ; input = replaceIgnoreCase ( input , " " , "

          " ) ; input = replaceIgnoreCase ( input , " " , "
          " ) ; input = replace ( input , " " ," " ) ; input = replace ( input , "\n" ,"
          " ) ; if ( input.indexOf("<") >= 0 ) { int oldPre = input.indexOf( "<" , 0 ) ; int oldEnd = input.indexOf( ">" , oldPre ) ; int tempInt = 0 ; StringBuffer setBlank = new StringBuffer () ; while ( oldPre >= 0 && oldEnd > 0 ) { setBlank = setBlank.append( input.substring( tempInt , oldPre) ) ; setBlank = setBlank.append ( replace ( input.substring( oldPre ,oldEnd ) , " " , " " ) ) ; tempInt = oldEnd ; oldPre = input.indexOf( "<" , oldEnd ) ; oldEnd = input.indexOf( ">" , oldPre ) ; } setBlank = setBlank.append ( input.substring( tempInt ) ) ; input = setBlank.toString() ; } } return input; } /*USE: *String convertURL( String input , boolean urlFlag ) */ public static String convertURL( String input , boolean urlFlag ) { if( input == null || input.length() == 0 || urlFlag || input.indexOf("[url") != -1 ) { return input; } else { StringBuffer buf = new StringBuffer(); int i = 0, j = 0, oldend = 0; int len = input.length(); char cur; while ( ( i=input.indexOf( "http://", oldend) ) >= 0 ) { j=i+7; cur = input.charAt(j); while (j < len) { if (cur == '' '') break; if (cur == ''<'') break; if (cur == ''\n'') break; if (cur == ''\r'' && j= 0 ) { j = i + tagPreLength ; j = input.indexOf( tagNameEnd , j ) ; if ( j < 0 ) { buf.append ( input.substring( oldend , len ) ) ; errorFlag = true ; break; } else { buf.append( input.substring(oldend,i)); buf.append( tagContentPre ); buf.append( input.substring(i + tagPreLength ,j)); buf.append( tagContentEnd ); buf.append( input.substring(i + tagPreLength ,j)).append( tagAttach ) ; } oldend = j + tagEndLength ; } if ( !errorFlag ) { buf.append(input.substring(j + tagEndLength,len)); } return buf.toString(); } catch ( IndexOutOfBoundsException IOBe ) { return input; } catch ( Exception e ) { return input; } } } // public static String convertSpecialTage ( String input , String tagNamePre , String tagNameEnd , String tagContentPre , String tagContentEnd ) { if( input == null || input.length() == 0 || input.indexOf( tagNamePre ) < 0 ) { return input; } else { try { StringBuffer buf = new StringBuffer(); int i = 0, j = 0, oldend = 0; int len = input.length(); int tagPreLength = tagNamePre.length() ; int tagEndLength = tagNameEnd.length() ; boolean errorFlag = false ; char cur; while ( ( i=input.indexOf( tagNamePre , oldend) ) >= 0 ) { j = i + tagPreLength ; j = input.indexOf( tagNameEnd , j ) ; if ( j < 0 ) { buf.append ( input.substring( oldend , len ) ) ; errorFlag = true ; break; } else { buf.append( input.substring(oldend,i)); buf.append( tagContentPre ); buf.append( input.substring(i + tagPreLength ,j)); buf.append( tagContentEnd ); } oldend = j + tagEndLength ; } if ( !errorFlag ) { buf.append( input.substring(j + tagEndLength,len)); } return buf.toString(); } catch ( IndexOutOfBoundsException IOBe ) { return input; } catch ( Exception e ) { return input; } } } // public static String convertSpecialTage ( String input , String tagNamePre , String tagNameEnd , String tagContentPre , String tagContentEnd , String tagAttach , String interval ) { if( input == null || input.length() == 0 || input.indexOf( tagNamePre ) < 0 ) { return input; } else { try { StringBuffer buf = new StringBuffer(); int i = 0, j = 0, oldend = 0; int len = input.length(); int tagPreLength = tagNamePre.length() ; int tagEndLength = tagNameEnd.length() ; int intervalLength = interval.length() ; boolean errorFlag = false ; String tempString = null ; char cur; while ( ( i=input.indexOf( tagNamePre , oldend) ) >= 0 ) { j = i + tagPreLength ; j = input.indexOf( tagNameEnd , j ) ; if ( j < 0 ) { buf.append ( input.substring( oldend , len ) ) ; errorFlag = true ; break; } else { int intervalPostion = input.indexOf( interval , i + tagPreLength ) ; if ( intervalPostion + intervalLength >= j ) { buf.append ( input.substring( oldend , len ) ) ; errorFlag = true ; break; } buf.append( input.substring(oldend,i)); buf.append( tagContentPre ); tempString = input.substring(i + tagPreLength ,intervalPostion ).trim() ; if ( tempString.indexOf("\"") == 0 ) { tempString = tempString.substring ( 1 , tempString.indexOf( "\"" , 1 ) ) ; } buf.append( tempString ); buf.append( tagContentEnd ); buf.append( input.substring( intervalPostion + intervalLength ,j ) ).append( tagAttach ) ; } oldend = j + tagEndLength ; } if ( !errorFlag ) { buf.append(input.substring(j + tagEndLength,len)); } return buf.toString(); } catch ( IndexOutOfBoundsException IOBe ) { return input; } catch ( Exception e ) { return input; } } } /*USE: *String convertIMG( String input ) */ public static String convertIMG ( String input ) { if( input == null || input.length() == 0 ) { return input; } else { return convertSpecialTage ( input , "" , "" ) ; } } /*USE: *String convertSupperUBB( String input , int level ) */ public static String convertSupperUBB ( String input , int level ) { if( input == null || input.length() == 0 ) { return input; } else { level++ ; if ( level-- > 0 ) input = convertSpecialTage ( input , "" , "" , "" , "" ) ; if ( level-- > 0 ) input = convertSpecialTage ( input , "[url=" , "][/url]" , "" , "" , "]" ) ; if ( level-- > 0 ) input = convertSpecialTage ( input , "[color=" ,"][/color]" , "" , "" , "]" ) ; if ( level-- > 0 ) input = convertSpecialTage ( input , "[size=" ,"][/size]" , "" , "" , "]" ) ; if ( level-- > 0 ) input = convertSpecialTage ( input , "" , "" , "" , "" ) ; if ( level-- > 0 ) input = convertSpecialTage ( input , "" , "" ) ; if ( level-- > 0 ) input = convertSpecialTage ( input , "[swf]" , "[/swf]" , "" ) ; if ( level-- > 0 ) input = convertSpecialTage ( input , "[url2]" , "[/url2]" , "" , "" ) ; if ( level-- > 0 ) input = convertSpecialTage ( input , "[url2=" , "][/url2]" , "" , "" , "]" ) ; if ( level-- > 0 ) input = convertSpecialTage ( input , "[a]" ,"[/a]" , "" ) ; if ( level-- > 0 ) input = convertSpecialTage ( input , "[div=" ,"][/div]" , "
          " , "
          " , "]" ) ; if ( level-- > 0 ) input = convertSpecialTage ( input , "[jsurl=" ,"][/jsurl]" , "" ,"" ,"]") ; if ( level-- > 0 ) input = convertSpecialTage ( input , "[class=" ,"][/class]" , "" , "" , "]" ) ; input = convertUBB ( input ) ; return input ; } } /*USE: *String convertMAIL( String input ) */ public static String convertMAIL ( String input ) { if( input == null || input.length() == 0 ) { return input; } else { return convertSpecialTage ( input , "" , "" , "" , "" ) ; } } /*USE: *String convertSWF( String input ) */ public static String convertSWF ( String input ) { if( input == null || input.length() == 0 ) { return input; } else { return convertSpecialTage ( input , "[swf]" , "[/swf]" , "" ) ; } } }
          posted @ 2005-07-13 16:03 方偉的博客 閱讀(571) | 評論 (1)編輯 收藏
          今天開始寫了
          posted @ 2005-07-13 15:55 方偉的博客 閱讀(548) | 評論 (1)編輯 收藏
          歡迎訪問!
          posted @ 2005-07-13 13:11 方偉的博客 閱讀(358) | 評論 (1)編輯 收藏
          僅列出標題
          共3頁: 上一頁 1 2 3 
          主站蜘蛛池模板: 绥棱县| 广河县| 车险| 石台县| 三门县| 城固县| 盘锦市| 邹平县| 大渡口区| 扶沟县| 金阳县| 城固县| 通渭县| 湘西| 曲麻莱县| 自治县| 西林县| 双流县| 莲花县| 阿克| 湘潭县| 星子县| 佛坪县| 巢湖市| 兴文县| 大丰市| 蒙山县| 探索| 肥西县| 女性| 卓资县| 舞钢市| 疏附县| 元氏县| 石台县| 汤原县| 屯留县| 建平县| 香港| 奉新县| 于都县|