java »ñµÃMAC Address
import java.net.InetAddress;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.StringTokenizer;
public final class NetworkInfo {
private final static String getMacAddress() throws IOException {
String os = System.getProperty("os.name");
try {
if (os.startsWith("Windows")) {
return windowsParseMacAddress(windowsRunIpConfigCommand());
} else if (os.startsWith("Linux")) {
return linuxParseMacAddress(linuxRunIfConfigCommand());
} else {
throw new IOException("unknown operating system: " + os);
}
} catch (ParseException ex) {
ex.printStackTrace();
throw new IOException(ex.getMessage());
}
}
/*
* Linux stuff
*/
private final static String linuxParseMacAddress(String ipConfigResponse)
throws ParseException {
String localHost = null;
try {
localHost = InetAddress.getLocalHost().getHostAddress();
} catch (java.net.UnknownHostException ex) {
ex.printStackTrace();
throw new ParseException(ex.getMessage(), 0);
}
StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n");
String lastMacAddress = null;
while (tokenizer.hasMoreTokens()) {
String line = tokenizer.nextToken().trim();
boolean containsLocalHost = line.indexOf(localHost) >= 0;
// see if line contains IP address
if (containsLocalHost && lastMacAddress != null) {
return lastMacAddress;
}
// see if line contains MAC address
int macAddressPosition = line.indexOf("HWaddr");
if (macAddressPosition <= 0)
continue;
String macAddressCandidate = line.substring(macAddressPosition + 6)
.trim();
if (linuxIsMacAddress(macAddressCandidate)) {
lastMacAddress = macAddressCandidate;
continue;
}
}
ParseException ex = new ParseException("cannot read MAC address for "
+ localHost + " from [" + ipConfigResponse + "]", 0);
ex.printStackTrace();
throw ex;
}
private final static boolean linuxIsMacAddress(String macAddressCandidate) {
// TODO: use a smart regular expre
Ïà¹ØÎĵµ£º
JAVA·´Éä»úÖÆ
¸ÅÊö
¡¡¡¡ÓÐʱºòÎÒÃÇ˵ij¸öÓïÑÔ¾ßÓкÜÇ¿µÄ¶¯Ì¬ÐÔ£¬ÓÐʱºòÎÒÃÇ»áÇø·Ö¶¯Ì¬ºÍ¾²Ì¬µÄ²»Í¬¼¼ÊõÓë×÷·¨¡£ÎÒÃÇÀÊÀÊÉϿڶ¯Ì¬°ó¶¨£¨dynamic binding£©¡¢¶¯Ì¬Á´½Ó£¨dynamic linking£©¡¢¶¯Ì¬¼ÓÔØ£¨dynamic loading£©µÈ¡£È»¶ø“¶¯Ì¬”Ò»´ÊÆäʵûÓоø¶Ô¶øÆÕ±éÊÊÓõÄÑϸñ¶¨Ò壬ÓÐʱºòÉõÖÁÏñ¶ÔÏóµ¼Ïòµ±³õ±»µ¼Èë±à³ ......
ÔÚʵÏÖsingletonģʽʱ£¬ÎÒÃÇÓÐÒÔϼ¸ÖÖ·½·¨¡£ 1. public static final ×ֶμÓÉÏprivate µÄ¹¹Ô캯Êý¡£ public class Singleton{
public static final Singleton INSTANCE = new Singleton();
......
PO(persistant object) ³Ö¾Ã¶ÔÏó
ÔÚ o/rÓ³ÉäµÄʱºò³öÏֵĸÅÄÈç¹ûûÓÐo/rÓ³É䣬ûÓÐÕâ¸ö¸ÅÄî´æÔÚÁË¡£Í¨³£¶ÔÓ¦Êý¾ÝÄ£ÐÍ(Êý¾Ý¿â),±¾Éí»¹Óв¿·ÖÒµÎñÂß¼µÄ´¦Àí¡£¿ÉÒÔ¿´³ÉÊÇÓëÊý¾Ý¿âÖеıíÏàÓ³ÉäµÄjava¶ÔÏó¡£×î¼òµ¥µÄPO¾ÍÊǶÔÓ¦Êý¾Ý¿âÖÐij¸ö±íÖеÄÒ»Ìõ¼Ç¼£¬¶à¸ö¼Ç¼¿ÉÒÔÓÃPOµÄ¼¯ºÏ¡£POÖÐÓ¦¸Ã²»°üº¬ÈκζÔÊý¾Ý¿âµÄ²Ù×÷¡£
......
¼ÓÃܺóÊÇÒ»¸ö32λ´óд×Öĸ×éºÏÐÎʽ£¬²¢ÇÒ±¾¼ÓÃÜ·½·¨²»¿ÉÄæ£¡
public String kljm(String dm,String kl)
{
String mw, cmm;
int k, i, tmp, a, hf, lf, bytes = 16;
int mm[], l,rand_seed;
rand_seed = 12345;
int len=kl.length();
if(len>=12) len=12;
mw =kl.substring(0,len) + dm.trim();
l = ......
Read-Write Lock PatternµÄ²ÎÓëÕߣº
1. Reader£¨¶ÁÈ¡Õߣ©²ÎÓëÕß
Reader²ÎÓëÕß»á¶ÔSharedResource²ÎÓëÕß½øÐÐread¡£
2. Writer£¨Ð´ÈëÕߣ©²ÎÓëÕß
Writer²ÎÓëÕß»á¶ÔSharedResource²ÎÓëÕß½øÐÐwrite¡£
3. SharedResource£¨¹²Ïí×ÊÔ´£©²ÎÓëÕß
SharedResource²ÎÓëÕß ......