JAVA Àïvolatile¹Ø¼ü×ÖÊÇʲôÒâ˼£¿
VolatileÐÞÊεijÉÔ±±äÁ¿ÔÚÿ´Î±»Ï̷߳ÃÎÊʱ£¬¶¼Ç¿ÆÈ´Ó¹²ÏíÄÚ´æÖÐÖضÁ¸Ã³ÉÔ±±äÁ¿µÄÖµ¡£¶øÇÒ£¬µ±³ÉÔ±±äÁ¿·¢Éú±ä»¯Ê±£¬Ç¿ÆÈÏ߳̽«±ä»¯Öµ»Øдµ½¹²ÏíÄÚ´æ¡£ÕâÑùÔÚÈκÎʱ¿Ì£¬Á½¸ö²»Í¬µÄÏß³Ì×ÜÊÇ¿´µ½Ä³¸ö³ÉÔ±±äÁ¿µÄͬһ¸öÖµ¡£
JavaÓïÑԹ淶ÖÐÖ¸³ö£ºÎªÁË»ñµÃ×î¼ÑËٶȣ¬ÔÊÐíÏ̱߳£´æ¹²Ïí³ÉÔ±±äÁ¿µÄ˽Óп½±´£¬¶øÇÒÖ»µ±Ï߳̽øÈë»òÕßÀ뿪ͬ²½´úÂë¿éʱ²ÅÓë¹²Ïí³ÉÔ±±äÁ¿µÄÔʼֵ¶Ô±È¡£
ÕâÑùµ±¶à¸öÏß³ÌͬʱÓëij¸ö¶ÔÏó½»»¥Ê±£¬¾Í±ØÐëҪעÒâµ½ÒªÈÃÏ̼߳°Ê±µÄµÃµ½¹²Ïí³ÉÔ±±äÁ¿µÄ±ä»¯¡£
¶øvolatile¹Ø¼ü×Ö¾ÍÊÇÌáʾVM£º¶ÔÓÚÕâ¸ö³ÉÔ±±äÁ¿²»Äܱ£´æËüµÄ˽Óп½±´£¬¶øÓ¦Ö±½ÓÓë¹²Ïí³ÉÔ±±äÁ¿½»»¥¡£
ʹÓý¨Ò飺ÔÚÁ½¸ö»òÕ߸ü¶àµÄÏ̷߳ÃÎʵijÉÔ±±äÁ¿ÉÏʹÓÃvolatile¡£µ±Òª·ÃÎʵıäÁ¿ÒÑÔÚsynchronized´úÂë¿éÖУ¬»òÕßΪ³£Á¿Ê±£¬²»±ØʹÓá£
ÓÉÓÚʹÓÃvolatileÆÁ±ÎµôÁËVMÖбØÒªµÄ´úÂëÓÅ»¯£¬ËùÒÔÔÚЧÂÊÉϱȽϵͣ¬Òò´ËÒ»¶¨ÔÚ±ØҪʱ²ÅʹÓô˹ؼü×Ö¡£
Ïà¹ØÎĵµ£º
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class ConvertMapToList {
/**
* ʵÏÖ½«HashMapת»»³ÉΪArrayList£¬²¢½«mapµÄKey ¡¢Value·Ö± ......
String s = new String("abc");
String s1 = "abc";
String s2 = new String("abc");
System.out.println(s == s1);
System.out.println(s == s2);
S ......
class NewTask extends java.util.TimerTask{
private String HOUR_MASK = "0";
private String MIN_MASK = "0";
private String SEC_MASK = "0";
private int hour;
private int min ......
Òþ²Ø´°ÌåÄÚµÄÊó±êÖ¸Õ룬ֱ½ÓÉÏ´úÂë
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.image.MemoryImageSource;
import javax.swing.JFrame;
public class HideCursor extends JFrame {
HideCursor() {
this.setBounds(300, 300, 300, 300);
&nb ......
»ù±¾Êý¾ÝµÄÀàÐ͵ĴóСÊǹ̶¨µÄ£¬ÕâÀï¾Í²»¶à˵ÁË¡£¶ÔÓÚ·Ç»ù±¾ÀàÐ͵ÄJava¶ÔÏó£¬Æä´óС¾ÍÖµµÃÉÌȶ¡£
ÔÚJavaÖУ¬Ò»¸ö¿ÕObject¶ÔÏóµÄ´óСÊÇ8byte£¬Õâ¸ö´óСֻÊDZ£´æ¶ÑÖÐÒ»¸öûÓÐÈκÎÊôÐԵĶÔÏóµÄ´óС¡£¿´ÏÂÃæÓï¾ä£º
Object ob = new Object();
ÕâÑùÔÚ³ÌÐòÖÐÍê³ÉÁËÒ»¸öJava¶ÔÏóµÄÉúÃü£¬µ«ÊÇËüËùÕ¼µÄ ......