ÔÚJavaÖÐËøÎļþµÄÀý×Ó
1.Èç¹ûÔÚÏÂÃæµÄ´úÂëÖУ¬tryLock¸Ä³Élock£¬ÄÇô»áÒ»Ö±µÈ´ý£¬Ö±µ½Äܹ»ËøÉÏÎļþΪֹ£¬µ«tryLock»áÁ¢¼´·µ»Ø¡£
Èç¹ûÒ»¸öµ÷ÓÃÁËtryLock£¬»òlock²¢Çҳɹ¦ËøÉÏÖ¸¶¨ÎļþºóµÄ³ÌÐò£¬ÔÚûÓÐÊÍ·ÅÎļþËøµÄÇé¿öÏ£¨Ã»Óе÷ÓÃrelease£©³ÌÐò¾Í½áÊø£¨°üº¬Ç¿ÖƽáÊøµÄÇé¿ö£©£¬ÄÇôÎļþËø»á×Ô¶¯±»ÊÍ·Å¡£
2.´úÂëÖеÄsleepÊÇΪÁ˱ãÓÚÑéÖ¤³ÌÐòÓõġ£±ÈÈ磬ÔÚsleep½×¶Î£¬Äã¿ÉÒÔÊÔ×ÅÐ޸ıðËøסµÄÎļþ²¢±£´æ¸ü¸Ä¡£»òÕßÔٴε÷Óñ¾³ÌÐòÀ´ÑéÖ¤¡£
±¾³ÌÐòÔÚÈçÏÂƽ̨ÏÂÑé֤ͨ¹ý£º
OS: Windwos XP
java version "1.6.0_20"
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
public class FileLock {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("##################### start. ");
if (args.length != 1) {
System.out.println("parameter is invalid.");
return;
}
RandomAccessFile input = null;
try {
input = new RandomAccessFile(args[0], "rw");
} catch (FileNotFoundException fe) {
System.out.println("file is not found.");
return;
}
FileChannel channel = input.getChannel();
java.nio.channels.FileLock lock = null;
try {
// Lock is existed, tryLock return null.
lock = channel.tryLock();
System.out.println("lock called.");
if (lock == null) {
System.out.println("lock is null");
return;
}
if (lock.isShared()) {
System.out.println("lock isShared.");
} else {
System.out.println("lock not Shared.");
}
if (lock.isValid()) {
System.out.println("lock isValid.");
} else {
System.out.println("lock Valid.");
}
try {
Thread.sleep(10000);
} catch (InterruptedException ie) {
System.out.println("InterruptedException.");
}
} catch (IOException ie) {
System.out.println("lock file failed.");
System.out.println(ie.toString());
} finally {
try {
if (lock != null) {
lock.release();
}
channel.close();
if (input
Ïà¹ØÎĵµ£º
1£¬Ê²Ã´ÊÇClone £¿
¼òµ¥µØ˵£¬ Clone ¾ÍÊǶÔÓÚ¸ø¶¨µÄÒ»¸ö¶ÔÏóʵÀý o £¬µÃµ½ÁíÒ»¸ö¶ÔÏóʵÀý o’ £º o Óë o’ Àà
ÐÍÏàͬ£¨ o.getClass() == o’.getClass() £©£¬ÄÚÈÝÏàͬ£¨¶ÔÓÚ o/o’ ÖеÄ×ֶΠf £¬Èç¹û f ÊÇ»ù±¾Êý¾ÝÀàÐÍ£¬Ôò o.f == o’.f £»Èç¹û f ÊǶÔÏóÒýÓã¬Ôò o.f == o’.f »ò o.f Ö ......
javaÊÔÌâ
http://202.201.112.11/jpk/apply/teacher/preface/53/test123/test3/exam.htm
1.½Ó¿ÚÖз½·¨µÄÇ°ÃæÓÐÄÄЩÐÞÊηû
·ÃÎÊȨÏÞ ·µ»ØÖµÀàÐÍ ÊÇ·ñ¾²Ì¬ ÊÇ·ñ³éÏó
2.ÒÔÏÂÄĸöΪÕæ
Interger a = new Interger(9);
Interger b = new Interger(9);
Long c = New Long(9)
-----
&nbs ......
ËïöÎÀÏʦ´Ó98Ä꿪ʼ´ÓÊÂÈí¼þ¿ª·¢¹¤×÷£¬¸ºÔ𲢿ª·¢µÄÏîÄ¿ÓУº
¡¡¡¡
1999Ä꣬²ÉÓÃsocket±à³ÌÍê³ÉÓïÒôË«Ïò·ÒëϵͳµÄÍøÂç´«Ê书ÄÜ¡£
¡¡¡¡2000Äê³õ£¬´ÓÊÂÓïÒôË«Ïò·ÒëϵͳµÄÕûÌ忪·¢£¬Ê¹ÓÃvcºÍ±ê×¼c£¬´ËÏîÄ¿¾ßÓм«¸ßµÄ¼¼Êõº¬Á¿£¬ÆäÖаüÀ¨ÁËÓïÒôʶ±ð¼¼Êõ£¬ÓïÒôºÏ³É¼¼Êõ£¬»úÆ÷·Òë¼¼Êõ£¬¶àýÌå²¥·ÅÓë´«Êä¼¼Êõ¡£²¢ÓÉ´Ë»ñµÃÁËÐÅÏ ......
±¾ÖÜÓöµ½Ò»¸öjavaÂÒÂëÎÊÌ⣬ÓÚÊǶÔjavaµÄ±àÂëÎÊÌâ×öÁËһЩʵÑéºÍÁ˽⡣¼òµ¥·ÖÎöÈçÏ£º
ÏÈ¿´ÏÂÈçÏ´úÂ룺
import
java.io.UnsupportedEncodingException;
public
class
CharSetTest {
public
static
void
main(String[] args)
throws
UnsupportedEncodingException {
String test =
"
ÀºÇò
" ......
1.2 ¹¤³§·½·¨£¨Factory Method£©Ä£Ê½
¹¤³§·½·¨Ä£Ê½ÊÇÀàµÄ´´½¨Ä£Ê½£¬ÓÖ½ÐÐéÄâ¹¹Ôì×Ó£¨Virtual Constructor£©Ä£Ê½»òÕ߶à̬ÐÔ¹¤³§£¨Polymorphic Factory£©Ä£Ê½¡£
¹¤³§·½·¨Ä£Ê½µÄÓÃÒâÊǶ¨ÒåÒ»¸ö´´½¨²úÆ·¶ÔÏóµÄ¹¤³§½Ó¿Ú£¬½«Êµ¼Ê¹¤×÷ÍƳٵ½×ÓÀàÖС£
1.2.1 ¹¤ ......