Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JavaÏß³Ìͬ²½Ê¾Àý

ÎÄÕÂÓÃʵÀý´úÂëչʾÁËJavaÖжàÏ̷߳ÃÎʹ²Ïí×ÊÔ´
ʱÏß³Ìͬ²½
µÄÖØÒªÐÔ¡£
·Ö±ðͨ¹ýÔÚÁ½¸öÏß³ÌÖÐͬʱ·ÃÎÊ(µ÷ÓÃget_id*·½·¨)¾­¹ýͬ²½´¦Àí(lock¼°Synchronized)µÄ¹²Ïí×ÊÔ´(tmp)¼°Î´¾­¹ýͬ²½´¦ÀíµÄ¹²Ïí×ÊÔ´(tmp)À´ËµÃ÷ͬ²½´¦ÀíµÄµÄ×÷Óá£
mainÖзÖÁ½²¿·Ö:
1£©Ç°°ë²¿·Ö£¬non-synchronization²¿·ÖÓÃÀ´²âÊÔûÓÐ×öͬ²½´¦ÀíµÄ´úÂë¶Î£¬ÔËÐнá¹ûÓ¦¸ÃÊÇ
After thread #1 call get_id(), id=1
After thread #2 call get_id(), id=1
2£©ºó°ë²¿·Ö£¬synchronization²¿·ÖÓÃÀ´²âÊÔ×ö¹ýͬ²½´¦ÀíµÄ´úÂë¶Î£¬ÔËÐнá¹ûÓ¦¸ÃÊÇ
After thread #1 call get_id(), id=1
After thread #2 call get_id(), id=2
²Î¿¼×ÊÁÏ£º
-1-¹ØÓÚsleepºÍwaitÇø±ð¿´Ò»ÏÂÕâ¸ö: http://wurd.javaeye.com/blog/174563¡£
-2-¹ØÓÚsynchronized¿ÉÒÔ¿´Ò»ÏÂÕâƪ£ºhttp://www.wangchao.net.cn/bbsdetail_148670.html£¬±È½ÏÃ÷ÁË¡£
-3-¹ØÓÚJavaÏß³Ìͬ²½¿ÉÒÔ¿´Ò»ÏÂÕâ¸ö£ºhttp://lavasoft.blog.51cto.com/62575/27069£¬ºÜÏêϸ¡£
/********************************************************************************
*FileName: Thread_sync.java
*Date: 2010/01/12
*Intention: Test thread synchronization tools in java.
*Input:
*Output:
* in non-synchronization version
* After thread #1 call get_id(), id=1
* After thread #2 call get_id(), id=1
* in synchronization version
* After thread #1 call get_id(), id=1
* After thread #2 call get_id(), id=2
*
*DevelopmentEnv: Netbeans 6.8, Jdk 1.6.
********************************************************************************/
class Counter
{
private final static Object lock = new Object();
private static int count = 0;

public int get_id()
{
int tmp = count;
++tmp;
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
}
count = tmp;

return count;
}
public int get_id_sync()
{
synchronized(lock)
{
int tmp = count;
++tmp;
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
}
count = tmp;
}

return count;
}
}
public class Thread_sync
{
private static int cnt = 0;
static class Rab implements Runnable
{


Ïà¹ØÎĵµ£º

¡¾×ª¡¿¸øJava°üÈ¡Ò»¸ö¶ÀÒ»ÎÞ¶þµÄÃû×Ö

À´Ô´£ºhttp://bbs.hackline.net/thread-3620-1-1.html
Òþ²Ø¾ßÌåʵÏÖÊÇJavaÓïÑÔµÄÖ÷ÒªÌصãÖ®Ò»¡£ÕýÊÇÒòΪÕâ¸öÔ­Òò£¬ËùÒÔJavaÓïÑÔµÄÒÆÖ²ÐÔ¾ÍÌرðºÃ¡£ÈçÓиö³ÌÐòÔ±±àдÁËÒ»¸öʵÏÖËæ»úÊýµÄ³ÌÐò¿â£¬ÄÇôÆäËû
³ÌÐò¿ª·¢ÈËÔ±Ö»ÐèÒªÖªµÀÕâ¸ö³ÌÐò¿âÐèÒª´«ÈëÄÇЩ²ÎÊý£¬¾Í¿ÉÒÔʹÓÃÕâ¸öÀà¡£ÏÖÔÚÎÞÂÛÊÇÍøÉÏ»¹ÊÇƽʱµÄ¹¤×÷ÖУ¬ÓкܶàÏÖ³É ......

JavaÕýÔòÑéÖ¤

import java.util.regex.*;

public final class RegExpValidator
{
/**
* ÑéÖ¤ÓÊÏä
* @param ´ýÑéÖ¤µÄ×Ö·û´®
* @return Èç¹ûÊÇ·ûºÏµÄ×Ö·û´®,·µ»Ø <b>true </b>,·ñÔòΪ <b>false </b>
*/
public static boolean isEmail(String str)
{ ......

JAVA¼ÓÃÜËã·¨»ã×ÜÒ»

1. MD5¼ÓÃÜ£¬³£ÓÃÓÚ¼ÓÃÜÓû§ÃûÃÜÂ룬µ±Óû§Ñé֤ʱ¡£
¡¡ ¡¡protected byte[] encrypt(byte[] obj) ...{
¡¡¡¡try ...{
¡¡¡¡MessageDigest md5 = MessageDigest.getInstance("MD5");
¡¡¡¡md5.update(obj);
¡¡¡¡return md5.digest();
¡¡¡¡} catch (NoSuchAlgorithmException e) ...{
¡¡¡¡e.printStackTrace();
¡ ......

¶¼ÊDZàÂëÈǵĻö java±à³Ì

    ×î½üÔÚÓÃÈóǬÔÚ×öһЩwebÏîÄ¿µÄ±¨±í£¬ÆäÖÐÓÐÒ»¸öÅúÁ¿´òÓ¡µÄ±¨±í¡£ÐèÒª°Ñ²ÎÊý´«µ½±¨±íÀµ±°ÑÖÐÎÄ´«µ½ÀïÃæʱ×ÜʱÂÒÂ룬²ÉÓÃÁ˸÷ÖÖתÂ뷽ʽ£¬Ò²Ã»×ª¹ýÀ´£¬ÔÎ.........
Ϊʲô»áÓÐÕâô¶àµÄ±àÂ룬ºÃÍ·ÌÛѽ... ......

JAVA ÕýÔò±í´ïʽ4ÖÖ³£ÓõŦÄÜ

ÕýÔò±í´ïʽÔÚ×Ö·û´®´¦ÀíÉÏÓÐ×ÅÇ¿´óµÄ¹¦ÄÜ£¬sunÔÚjdk1.4¼ÓÈëÁ˶ÔËüµÄÖ§³Ö
ÏÂÃæ¼òµ¥µÄ˵ÏÂËüµÄ4ÖÖ³£Óù¦ÄÜ£º
²éѯ£º
ÒÔÏÂÊÇ´úÂëƬ¶Î£º
String str="abc efg ABC";
String regEx="a|f"; //±íʾa»òf
Pattern p=Pattern.compile(regEx);
Matcher m=p.matcher(str);
boolean rs=m.find();
Èç¹ûstrÖÐÓÐregEx£¬ÄÇôrsΪtru ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ