JavaÉè¼Æģʽ֮Singletonµ¥Àýģʽƪ
JavaÉè¼Æģʽ֮Singletonµ¥Àýģʽƪ
java µ¥ÀýģʽµÄʵÏÖ·½Ê½
ʵÏÖ1£º
public class Singleton {
private static Singleton instance;
private Singleton (){ //Ê×ÏÈÓÐÒ»¸ö˽ÓеĹ¹ÔìÆ÷
}
public static Singleton getInstance() {
if(instance==null){
instance=new Singleton ();
}
return instance;
}
}
ÕâÖÖ·½Ê½ÊÇÏ̲߳»°²È«µÄ£¬Èç¹û¶à¸öÏß³Ìͬʱ·ÃÎʵĻ°¾Í¿ÉÄÜÓжà¸ö¶ÔÏó²úÉú£¬Èç¹ûÔÚget·½·¨ÖмÓͬ²½¿éµÄ»°»áÓ°ÏìÐÔÄÜ¡£
ʵÏÖ2£º
public class Singleton {
private Singleton(){
}
private static Singleton instance =new Singleton();
public static Singleton getInstance(){
return instance;
}
}
ÕâÖÖ·½Ê½ËäÈ»²»´æÔÚ°²È«ÐÔÎÊÌ⣬µ«ÊÇÔÚ³ÌÐòÆô¶¯µÄʱºò¾Í»á³õʼ»¯¡£
ʵÏÖ3£º
public class Singleton {
private static class SingletonHolder {
static Singleton instance = new Singleton();
}
public static Singleton getInstance() {
return SingletonHolder.instance;
}
}
3ÖÖ·½Ê½ÖÐÕâÊÇ×îºÃµÄ½â¾ö·½°¸£¬¼È½â¾öÁËÏß³Ìͬ²½µÄÎÊÌ⣬ÓÐÔÚµ÷ÓõÄʱºò²Å³õʼ»¯¡£
µ¥ÀýģʽÖ÷ÒªÓÐ3¸öÌص㣬£º
1¡¢µ¥ÀýÀàÈ·±£×Ô¼ºÖ»ÓÐÒ»¸öʵÀý¡£
2¡¢µ¥ÀýÀà±ØÐë×Ô¼º´´½¨×Ô¼ºµÄʵÀý¡£
3¡¢µ¥ÀýÀà±ØÐëΪÆäËû¶ÔÏóÌṩΨһµÄʵÀý¡£
ʲôʱºòʹÓõ¥Àýģʽ£¿
µ¥ÀýģʽҲÊÇÒ»ÖֱȽϳ£¼ûµÄÉè¼Æģʽ£¬Ëüµ½µ×ÄÜ´ø¸øÎÒÃÇʲôºÃ´¦ÄØ£¿ÆäʵÎÞ·ÇÊÇÈý¸ö·½ÃæµÄ×÷Óãº
µÚÒ»¡¢¿ØÖÆ×ÊÔ´µÄʹÓã¬Í¨¹ýÏß³Ìͬ²½À´¿ØÖÆ×ÊÔ´µÄ²¢·¢·ÃÎÊ£»
µÚ¶þ¡¢¿ØÖÆʵÀý²úÉúµÄÊýÁ¿£¬´ïµ½½ÚÔ¼×ÊÔ´µÄÄ¿µÄ¡£
µÚÈý¡¢×÷ΪͨÐÅý½éʹÓã¬Ò²¾ÍÊÇÊý¾Ý¹²Ïí£¬Ëü¿ÉÒÔÔÚ²»½¨Á¢Ö±½Ó¹ØÁªµÄÌõ¼þÏ£¬Èöà¸ö²»Ïà¹ØµÄÁ½¸öÏ̻߳òÕß½ø³ÌÖ®¼äʵÏÖͨÐÅ¡£
±È È磬Êý¾Ý¿âÁ¬½Ó³ØµÄÉè¼ÆÒ»°ã²ÉÓõ¥Àýģʽ£¬Êý¾Ý¿âÁ¬½ÓÊÇÒ»ÖÖÊý¾Ý¿â×ÊÔ´¡£Èí¼þϵͳÖÐʹÓÃÊý¾Ý¿âÁ¬½Ó³Ø£¬Ö÷ÒªÊǽÚÊ¡´ò¿ª»òÕ߹رÕÊý¾Ý¿âÁ¬½ÓËùÒýÆðµÄЧÂÊËð ºÄ£¬ÕâÖÖЧÂÊÉϵÄËðºÄ»¹ÊǷdz£°º¹óµÄ¡£µ±È»£¬Ê¹ÓÃÊý¾Ý¿âÁ¬½Ó³Ø»¹ÓкܶàÆäËüµÄºÃ´¦£¬¿ÉÒÔÆÁ±Î²»Í¬Êý¾ÝÊý¾Ý¿âÖ®¼äµÄ²îÒ죬ʵÏÖϵͳ¶ÔÊý¾Ý¿âµÄµÍ¶ÈñîºÏ£¬Ò²¿É
Ïà¹ØÎĵµ£º
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet. ......
²é¿´×îо«»ªÎÄÕ Çë·ÃÎʲ©¿ÍÊ×Ò³Ïà¹ØÎÄÕ ͨÓøßУÅÅ¿ÎËã·¨Ñо¿----Ç°ÑÔjava cloneÏê½âÈ«ÃæÉîÈë½éÉÜC++×Ö·û´®£ºstringÀàÔƼÆËãµ¼ÂÛFreeMarker±Ê¼Ç²ÔÓ¥-GISRenÂþ»°GISÁÖÊÏÎïÓï.³¯»¨Ï¦Ê°Ö®ºÞ·êÇäÍíÎ人¾¹Éý¹«Ë¾ WebSphere Portal ÄÚÈݹÜÀíÉý¼¶ÊµÊ©·½°¸ ......
ÔÚJSPÀ»ñÈ¡¿Í»§¶ËµÄIPµØÖ·µÄ·½·¨ÊÇ£ºrequest.getRemoteAddr£¨£©£¬ÕâÖÖ·½·¨Ôڴ󲿷ÖÇé¿ö϶¼ÊÇÓÐЧµÄ¡£µ«ÊÇÔÚͨ¹ýÁËApache£¬SquidµÈ·´Ïò´úÀíÈí¼þ¾Í²»ÄÜ»ñÈ¡µ½¿Í»§¶ËµÄÕæʵIPµØÖ·ÁË¡£
¡¡¡¡
Tag£ºJava ¿Í»§¶Ë ÕæʵIPµØÖ·
ÔÚJSPÀ»ñÈ¡¿Í»§¶ËµÄIPµØÖ·µÄ·½·¨ÊÇ£ºrequest.getRemoteAddr£¨£©£¬ÕâÖÖ·½·¨Ôڴ󲿷ÖÇé¿ ......
javaÑéÖ¤ÂëµÄʵÏÖ(Ò»)
ÊÕ²Ø
1.ImageServletÀàµÄʵÏÖ£º
package com.mobile.control;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOExcep ......