JavaÖеÄʱ¼ä¾«¶È
ÔÚJavaÖпÉÒÔͨ¹ýSystem.currentTimeMillis()»òÕßSystem.nanoTime() (JDK>=5.0) ·½·¨»ñµÃµ±Ç°µÄʱ¼äµÄ¾«È·Öµ¡£µ«ÊÇͨ¹ýÔĶÁJavadoc£¬ÎÒÃÇ·¢ÏÖÕâÁ½¸ö·½·¨²¢²»Ò»¶¨±£Ö¤µÃµ½ÄãËùÆÚÍûµÄ¾«¶È¡£ÏÈÀ´¿´System.currentTimeMillis()£º
Returns the current time in milliseconds. Note that while the unit of time of
the return value is a millisecond, the granularity of the value depends on the
underlying operating system and may be larger. For example, many operating
systems measure time in units of tens of milliseconds.
³ÏÈçÉÏÃæËù˵·µ»ØÖµµÄÁ£¶ÈÒÀÀµÓڵײã²Ù×÷ϵͳ£¬ÄÇôËüÔÚ²»Í¬µÄƽ̨Éϵ½µ×ÄÜÌṩÊÇôÑùµÄ¾«¶È£¬ÊÇ·ñÏñº¯ÊýÃûËùдµÄÄÇÑùÕæÕý
¾«
È·µ½1ºÁÃëÄØ£¿¿´ÏÂÃæÒ»¶Î²âÊÔ³ÌÐò£º
public class ClockAccuracyTest {
public static void main(String args[]) {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss:SSS");
int size = 4000000;
// create an array to hold millisecond times
// and loop to capture them
long times[] = new long[size];
for (int i = 0; i < size; i++) {
times[i] = System.currentTimeMillis();
}
// now display the unique times
long time = times[0];
long previousTime = times[0];
long count = 0;
Set<Long> deltas = new HashSet<Long>();
long delta = 0;
long minDelta = Long.MAX_VALUE;
long maxDelta = Long.MIN_VALUE;
&
Ïà¹ØÎĵµ£º
ÀàÐÍת»»×ܽ᣺
1.ÔÐÍÊý¾Ýbyte,short,int,long,float,double,char,boolean,СÀàÐÍÊý¾Ý¿ÉÒÔÖ±½Ó¸³¸ø´óÀàÐÍÊý¾ÝÀýÈç
int a=1;byte b=2;short c=3;float d=3;double e=4;char f='a';boolean g=true;long l=10;
c=b;
a=f;
d=a;
e=d;
byteÐÍÊý¾Ý²»ÄÜÖ±½Ó¸³¸øcharÐÍÊý¾Ý£¬ÒòΪbyte±íʾµÄÊÇ8λÓзûºÅÊý£¬¶øchar±íʾµ ......
¶ÔÓÚÒ»¸öʵÏÖÁËComparable½Ó¿ÚµÄ¶ÔÏ󣬸ýӿÚÖ»ÄÜʵÏÖÒ»´Î¡£Èç¹ûÔÚÒ»¸ö¼¯ºÏÀïÃæÐèҪʹÓÃidÅÅÐò£¬¶øÔÚÁíÍâÒ»¸ö¼¯ºÏÀïÐèÒª°´Ãû×ÖÅÅÐòÕâʱ¾ÍÐèÒªÔÚÕâ¸ö¼¯ºÏÀïÃæÖ¸¶¨±È½ÏÆ÷¡£
Comparable½Ó¿ÚÉùÃ÷ÁËcompareTo(Object o)·½·¨
Comparator ½Ó¿ÚÉùÃ÷ÁËcompare(Object o1,Object o2)·½·¨
eg:
µÚÒ»¸öÊ÷¼¯Êǰ´ÕÕ¶ÔÏóĬÈϵÄidÅÅÐò£¬µ ......
Ò»¡¢JavaÔËÐÐʱµÄÁ½ÖÖºËÐÄ»úÖÆ
£¨1£©JavaÐéÄâ»ú£¨Java Virtual Machine£©
ÓÃÀ´´¦ÀíJavaÔ´Îļþ±àÒëºóµÄ×Ö½ÚÂ룬ÆÁ±Îµ×²ãÔËÐÐÆ½Ì¨µÄ²îÒ죬ʵÏÖ“Ò»´Î±àÒë£¬Ëæ´¦Ö´ÐД£¬¶øÇÒ²»Í¬µÄÔËÐÐÆ ......
public class DateTest {
public static void main(String[] args) {
Date date = new Date(); // н¨Ò»¸öÈÕÆÚ
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // ¸ñʽ»¯ÈÕÆÚ
String beforeDate = sdf.format(getDateBefore(date, 10));
System ......
µÚ8Õ ¶àÏß³Ì
(Ò»)¿Î³ÌÄÚÈÝ
8.1Ï̵߳Ļù±¾¸ÅÄî
8.1.1Ï̵߳ÄÉúÃüÖÜÆÚ
8.1.2Ï̵߳÷¶ÈÓëÓÅÏȼ¶
8.2 ThreadÀàºÍRunnable½Ó13
8.2.1 ThreadÀà
8.2.2 Runnable½Ó¿Ú
8.3Ï̻߳¥³âºÍͬ²½
8.3.1Ï̻߳¥³â
8.3.2Ïß³Ìͬ²½
(¶þ)ѧϰĿµÄÓëÒªÇó
±¾Õ½éÉܶàÏ̵߳ĸÅÄîºÍ±àд¶àÏ̳߳ÌÐòµÄ·½·¨£¬ÊµÏÖÏß³ÌÖ®¼äÏ໥ͨÐźÍͬ²½µÄ¼¼ ......