JavaỊ̈߳ºÐÂÌØÕ÷ Ï̳߳Ø
JavaỊ̈߳ºÐÂÌØÕ÷-Ï̳߳Ø
SunÔÚJava5ÖУ¬¶ÔJavaÏ̵߳ÄÀà¿â×öÁË´óÁ¿µÄÀ©Õ¹£¬ÆäÖÐÏ̳߳ؾÍÊÇJava5µÄÐÂÌØÕ÷Ö®Ò»£¬³ýÁËÏ̳߳ØÖ®Í⣬»¹Óкܶà¶àÏß³ÌÏà¹ØµÄÄÚÈÝ£¬Îª¶àÏ̵߳ıà³Ì´øÀ´Á˼«´ó±ãÀû¡£ÎªÁ˱àд¸ßЧÎȶ¨¿É¿¿µÄ¶àÏ̳߳ÌÐò£¬Ï̲߳¿·ÖµÄÐÂÔöÄÚÈÝÏÔµÃÓÈΪÖØÒª¡£
ÓйØJava5Ïß³ÌÐÂÌØÕ÷µÄÄÚÈÝÈ«²¿ÔÚjava.util.concurrentÏÂÃ棬ÀïÃæ°üº¬ÊýÄ¿ÖÚ¶àµÄ½Ó¿ÚºÍÀ࣬ÊìϤÕⲿ·ÖAPIÌØÕ÷ÊÇÒ»Ïî¼èÄѵÄѧϰ¹ý³Ì¡£Ä¿Ç°ÓйØÕâ·½ÃæµÄ×ÊÁϺÍÊé¼®¶¼ÉÙÖ®ÓÖÉÙ£¬´óËùÊô½éÉÜÏ̷߳½ÃæÊé¼®»¹Í£ÁôÔÚjava5֮ǰµÄ֪ʶ²ãÃæÉÏ¡£
µ±È»ÐÂÌØÕ÷¶Ô×ö¶àÏ̳߳ÌÐòûÓбØÐëµÄ¹Øϵ£¬ÔÚjava5֮ǰͨÓÿÉÒÔд³öºÜÓÅÐãµÄ¶àÏ̳߳ÌÐò¡£Ö»ÊÇ´ú¼Û²»Ò»Ñù¶øÒÑ¡£
Ï̳߳صĻù±¾Ë¼Ï뻹ÊÇÒ»ÖÖ¶ÔÏó³ØµÄ˼Ï룬¿ª±ÙÒ»¿éÄÚ´æ¿Õ¼ä£¬ÀïÃæ´æ·ÅÁËÖڶࣨδËÀÍö£©µÄỊ̈߳¬³ØÖÐÏß³ÌÖ´Ðе÷¶ÈÓɳعÜÀíÆ÷À´´¦Àí¡£µ±ÓÐÏß³ÌÈÎÎñʱ£¬´Ó³ØÖÐÈ¡Ò»¸ö£¬Ö´ÐÐÍê³ÉºóÏ̶߳ÔÏó¹é³Ø£¬ÕâÑù¿ÉÒÔ±ÜÃâ·´¸´´´½¨Ï̶߳ÔÏóËù´øÀ´µÄÐÔÄÜ¿ªÏú£¬½ÚÊ¡ÁËϵͳµÄ×ÊÔ´¡£
ÔÚJava5֮ǰ£¬ÒªÊµÏÖÒ»¸öÏ̳߳ØÊÇÏ൱ÓÐÄѶȵģ¬ÏÖÔÚJava5ΪÎÒÃÇ×öºÃÁËÒ»ÇУ¬ÎÒÃÇÖ»ÐèÒª°´ÕÕÌṩµÄAPIÀ´Ê¹Ó㬼´¿ÉÏíÊÜÏ̳߳شøÀ´µÄ¼«´ó±ãÀû¡£
Java5µÄÏ̳߳طֺöàÖÖ£º¹Ì¶¨³ß´çµÄÏ̳߳ء¢¿É±ä³ß´çÁ¬½Ó³Ø¡¢¡£
ÔÚʹÓÃÏ̳߳Ø֮ǰ£¬±ØÐëÖªµÀÈçºÎÈ¥´´½¨Ò»¸öÏ̳߳أ¬ÔÚJava5ÖУ¬ÐèÒªÁ˽âµÄÊÇjava.util.concurrent.ExecutorsÀàµÄAPI£¬Õâ¸öÀàÌṩ´óÁ¿´´½¨Á¬½Ó³ØµÄ¾²Ì¬·½·¨£¬ÊDZØÐëÕÆÎյġ£
Ò»¡¢¹Ì¶¨´óСµÄÏ̳߳Ø
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
/**
* JavaỊ̈߳ºÏ̳߳Ø-
*
* @author Administrator 2009-11-4 23:30:44
*/
public class Test {
public static void main(String[] args) {
//´´½¨Ò»¸ö¿ÉÖØÓù̶¨Ïß³ÌÊýµÄÏ̳߳Ø
ExecutorService pool = Executors.newFixedThreadPool(2);
//´´½¨ÊµÏÖÁËRunnable½Ó¿Ú¶ÔÏó£¬Thread¶ÔÏóµ±È»Ò²ÊµÏÖÁËRunnable½Ó¿Ú
&
Ïà¹ØÎĵµ£º
1.Ì⣺javaÀúÊ·£¿
´ð£ºJava Ö®¸¸Golsling
1995 Äê5 ÔÂ23 ÈÕ Java µ®Éú
1998 Äê12 ÔÂ 1.2 °æ±¾Java2 J2SE J2EE J2ME
2004 Äê12 ÔÂ 1.5 °æ±¾(5.0) Java JavaSE JavaEE JavaME
2.Ì⣺JavaSE£¬JavaEE£¬JavaME£¿
´ð£ºJavaSE ---Java ±ê׼ƽ̨
JavaEE ---ÆóÒµ¼ ......
Java 1.5ÒÔÉ϶¼ÔÚÐéÄâ»úÀïÄÚ½¨Á˳ÌÐòÐÔÄܸú×ٵŦÄÜ£¬²¢ÌṩÁËJava Profiling API£¬¼ò³ÆJPA£¬Äã¿ÉÒÔËÑË÷'java
profiling'¡£JavaÒ²ÌṩÁ˼òµ¥µÄÐÔÄÜÐÔÄܸú×Ù¹¤¾ßJConsole£¬ÄÜÏÔʾÄڴ棬Ï̵߳ÈʹÓÃ×´¿ö¡£ÁíÍâÒ²ÊÇÓÉSunÌṩ£¬µ«²»°üº¬ÔÚjdk
ÀïµÄ¹¤¾ßvisualgc¿ÉÒÔͼÐη½Ê½ÏÔʾÀ¬»øÊÕ¼¯µÄÔËÐÐÇé¿ö£¬ÎªÐÔÄÜ·ÖÎöÌṩ֧³Ö¡£µÚÈý· ......
JavaỊ̈߳ºÏ̵߳Äͬ²½ÓëËø
Ò»¡¢Í¬²½ÎÊÌâÌá³ö
Ï̵߳Äͬ²½ÊÇΪÁË·ÀÖ¹¶à¸öÏ̷߳ÃÎÊÒ»¸öÊý¾Ý¶ÔÏóʱ£¬¶ÔÊý¾ÝÔì³ÉµÄÆÆ»µ¡£
ÀýÈ磺Á½¸öÏß³ÌThreadA¡¢ThreadB¶¼²Ù×÷ͬһ¸ö¶ÔÏóFoo¶ÔÏ󣬲¢ÐÞ¸ÄFoo¶ÔÏóÉϵÄÊý¾Ý¡£
public class Foo {
private int x = 100;
......
JavaỊ̈߳ºÏ̵߳ĵ÷¶È-ÓÅÏȼ¶
ÓëÏß³ÌÐÝÃßÀàËÆ£¬Ï̵߳ÄÓÅÏȼ¶ÈÔÈ»ÎÞ·¨±£ÕÏÏ̵߳ÄÖ´ÐдÎÐò¡£Ö»²»¹ý£¬ÓÅÏȼ¶¸ßµÄÏ̻߳ñÈ¡CPU×ÊÔ´µÄ¸ÅÂʽϴó£¬ÓÅÏȼ¶µÍµÄ²¢·Çû»ú»áÖ´ÐС£
Ï̵߳ÄÓÅÏȼ¶ÓÃ1-10Ö®¼äµÄÕûÊý±íʾ£¬ÊýÖµÔ½´óÓÅÏȼ¶Ô½¸ß£¬Ä¬ÈϵÄÓÅÏȼ¶Îª5¡£
ÔÚÒ»¸öÏß³ÌÖпªÆôÁíÍâÒ»¸öÐÂỊ̈߳¬ÔòпªÏ̳߳ÆÎ ......
JavaỊ̈߳ºÏ̵߳ĵ÷¶È-Èò½
Ï̵߳ÄÈò½º¬Òå¾ÍÊÇʹµ±Ç°ÔËÐÐ×ÅÏß³ÌÈóöCPU×ÊÔ´£¬µ«ÊÇÈ»¸ø˲»ÖªµÀ£¬½ö½öÊÇÈóö£¬Ïß³Ì״̬»Øµ½¿ÉÔËÐÐ״̬¡£
Ï̵߳ÄÈò½Ê¹ÓÃThread.yield()·½·¨£¬yield() Ϊ¾²Ì¬·½·¨£¬¹¦ÄÜÊÇÔÝÍ£µ±Ç°ÕýÔÚÖ´ÐеÄÏ̶߳ÔÏ󣬲¢Ö´ÐÐÆäËûÏ̡߳£
/**
* JavaỊ̈߳ºÏ̵߳ĵ÷¶È-Èò½
*
......