JavaỊ̈߳ºÐÂÌØÕ÷ Óзµ»ØÖµµÄÏß³Ì
JavaỊ̈߳ºÐÂÌØÕ÷-Óзµ»ØÖµµÄÏß³Ì
ÔÚJava5֮ǰ£¬Ïß³ÌÊÇûÓзµ»ØÖµµÄ£¬³£³£ÎªÁË“ÓД·µ»ØÖµ£¬ÆÆ·ÑÖÜÕÛ£¬¶øÇÒ´úÂëºÜ²»ºÃд¡£»òÕ߸ɴàÈƹýÕâµÀ¿²£¬×ß±ðµÄ·ÁË¡£
ÏÖÔÚJavaÖÕÓÚÓпɷµ»ØÖµµÄÈÎÎñ£¨Ò²¿ÉÒÔ½Ð×öỊ̈߳©ÁË¡£
¿É·µ»ØÖµµÄÈÎÎñ±ØÐëʵÏÖCallable½Ó¿Ú£¬ÀàËƵģ¬ÎÞ·µ»ØÖµµÄÈÎÎñ±ØÐëRunnable½Ó¿Ú¡£
Ö´ÐÐCallableÈÎÎñºó£¬¿ÉÒÔ»ñÈ¡Ò»¸öFutureµÄ¶ÔÏó£¬ÔڸöÔÏóÉϵ÷ÓÃget¾Í¿ÉÒÔ»ñÈ¡µ½CallableÈÎÎñ·µ»ØµÄObjectÁË¡£
ÏÂÃæÊǸöºÜ¼òµ¥µÄÀý×Ó£º
import java.util.concurrent.*;
/**
* JavaỊ̈߳ºÓзµ»ØÖµµÄÏß³Ì
*
* @author Administrator 2009-11-5 0:41:50
*/
public class Test {
public static void main(String[] args) throws ExecutionException, InterruptedException {
//´´½¨Ò»¸öÏ̳߳Ø
ExecutorService pool = Executors.newFixedThreadPool(2);
//´´½¨Á½¸öÓзµ»ØÖµµÄÈÎÎñ
Callable c1 = new MyCallable("A");
Callable c2 = new MyCallable("B");
//Ö´ÐÐÈÎÎñ²¢»ñÈ¡Future¶ÔÏó
Future f1 = pool.submit(c1);
Future f2 = pool.submit(c2);
//´ÓFuture¶ÔÏóÉÏ»ñÈ¡ÈÎÎñµÄ·µ»ØÖµ£¬²¢Êä³öµ½¿ØÖÆ̨
&
Ïà¹ØÎĵµ£º
´ò¿ªeclipse£¬·¢ÏÖeclipseå´µôÁË£¬²¢ÇÒ³öÏÖÕâÑùµÄÌáʾ£º¹ØÓÚInitializing java tooling£¨1%£©...
ÖØÆôÁ˼¸´ÎÖ®ºó·¢ÏÖÎÊÌâÈÔÈ»´æÔÚ£¬Òò¶ø¿ñËÑÁËÒ»°Ñ£¬ÖÕÓÚÕÒµ½ÕýÈ·µÄ½â¾ö°ì·¨£¬ÈçÏ£º
ÕÒµ½eclipseĿ¼£¬±à¼eclipse.iniÎļþ£¬ÔÚ-vmargs²ÎÊý֮ǰÌí¼ÓÉÏÈçϲÎÊý£¨Ò»¶¨ÒªÏñÏÂÃæÕâÑùд³ÉÁ½ÐУ©£¬È»ºóÖØÆô¾ÍokÁË
-vm
C:\Progr ......
Java 1.5ÒÔÉ϶¼ÔÚÐéÄâ»úÀïÄÚ½¨Á˳ÌÐòÐÔÄܸú×ٵŦÄÜ£¬²¢ÌṩÁËJava Profiling API£¬¼ò³ÆJPA£¬Äã¿ÉÒÔËÑË÷'java
profiling'¡£JavaÒ²ÌṩÁ˼òµ¥µÄÐÔÄÜÐÔÄܸú×Ù¹¤¾ßJConsole£¬ÄÜÏÔʾÄڴ棬Ï̵߳ÈʹÓÃ×´¿ö¡£ÁíÍâÒ²ÊÇÓÉSunÌṩ£¬µ«²»°üº¬ÔÚjdk
ÀïµÄ¹¤¾ßvisualgc¿ÉÒÔͼÐη½Ê½ÏÔʾÀ¬»øÊÕ¼¯µÄÔËÐÐÇé¿ö£¬ÎªÐÔÄÜ·ÖÎöÌṩ֧³Ö¡£µÚÈý· ......
JavaỊ̈߳ºÏ̵߳ĵ÷¶È-Èò½
Ï̵߳ÄÈò½º¬Òå¾ÍÊÇʹµ±Ç°ÔËÐÐ×ÅÏß³ÌÈóöCPU×ÊÔ´£¬µ«ÊÇÈ»¸ø˲»ÖªµÀ£¬½ö½öÊÇÈóö£¬Ïß³Ì״̬»Øµ½¿ÉÔËÐÐ״̬¡£
Ï̵߳ÄÈò½Ê¹ÓÃThread.yield()·½·¨£¬yield() Ϊ¾²Ì¬·½·¨£¬¹¦ÄÜÊÇÔÝÍ£µ±Ç°ÕýÔÚÖ´ÐеÄÏ̶߳ÔÏ󣬲¢Ö´ÐÐÆäËûÏ̡߳£
/**
* JavaỊ̈߳ºÏ̵߳ĵ÷¶È-Èò½
*
......
JavaỊ̈߳ºÏ̵߳ĵ÷¶È-ÊØ»¤Ïß³Ì
ÊØ»¤Ïß³ÌÓëÆÕͨÏß³Ìд·¨ÉÏ»ù±¾Ã´É¶Çø±ð£¬µ÷ÓÃÏ̶߳ÔÏóµÄ·½·¨setDaemon(true)£¬Ôò¿ÉÒÔ½«ÆäÉèÖÃΪÊØ»¤Ï̡߳£
ÊØ»¤Ïß³ÌʹÓõÄÇé¿ö½ÏÉÙ£¬µ«²¢·ÇÎÞÓ㬾ÙÀýÀ´Ëµ£¬JVMµÄÀ¬»ø»ØÊÕ¡¢ÄÚ´æ¹ÜÀíµÈÏ̶߳¼ÊÇÊØ»¤Ï̡߳£»¹ÓоÍÊÇÔÚ×öÊý¾Ý¿âÓ¦ÓÃʱºò£¬Ê¹ÓõÄÊý¾Ý¿âÁ¬½Ó³Ø£¬Á¬½Ó³Ø±¾ÉíÒ²°üº ......
JavaỊ̈߳ºÏ̵߳Äͬ²½-ͬ²½·½·¨
Ï̵߳Äͬ²½ÊDZ£Ö¤¶àḬ̈߳²È«·ÃÎʾºÕù×ÊÔ´µÄÒ»ÖÖÊֶΡ£
Ï̵߳Äͬ²½ÊÇJava¶àÏ̱߳à³ÌµÄÄѵ㣬ÍùÍù¿ª·¢Õ߸㲻Çå³þʲôÊǾºÕù×ÊÔ´¡¢Ê²Ã´Ê±ºòÐèÒª¿¼ÂÇͬ²½£¬Ôõôͬ²½µÈµÈÎÊÌ⣬µ±È»£¬ÕâЩÎÊÌâûÓкÜÃ÷È·µÄ´ð°¸£¬µ«ÓÐЩÔÔòÎÊÌâÐèÒª¿¼ÂÇ£¬ÊÇ·ñÓоºÕù×ÊÔ´±»Í¬Ê±¸Ä¶¯µÄÎÊÌ⣿
ÔÚ± ......