JavaỊ̈߳ºÐÂÌØÕ÷ Ô×ÓÁ¿
JavaỊ̈߳ºÐÂÌØÕ÷-Ô×ÓÁ¿
ËùνµÄÔ×ÓÁ¿¼´²Ù×÷±äÁ¿µÄ²Ù×÷ÊÇ“Ô×ӵĔ£¬¸Ã²Ù×÷²»¿ÉÔÙ·Ö£¬Òò´ËÊÇḬ̈߳²È«µÄ¡£
ΪºÎҪʹÓÃÔ×Ó±äÁ¿ÄØ£¬ÔÒòÊǶà¸öÏ̶߳Ե¥¸ö±äÁ¿²Ù×÷Ò²»áÒýÆðһЩÎÊÌâ¡£ÔÚJava5֮ǰ£¬¿ÉÒÔͨ¹ývolatile¡¢synchronized¹Ø¼ü×ÖÀ´½â¾ö²¢·¢·ÃÎʵݲȫÎÊÌ⣬µ«ÕâÑùÌ«Âé·³¡£
Java5Ö®ºó£¬×¨ÃÅÌṩÁËÓÃÀ´½øÐе¥±äÁ¿¶àÏ̲߳¢·¢°²È«·ÃÎʵŤ¾ß°üjava.util.concurrent.atomic£¬ÆäÖеÄÀàÒ²ºÜ¼òµ¥¡£
ÏÂÃæ¸ø³öÒ»¸ö·´ÃæÀý×Ó£¨ÇÐÎðÄ£·Â£©£º
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
/**
* JavaỊ̈߳ºÐÂÌØÕ÷-Ô×ÓÁ¿
*
* @author leizhimin 2009-11-6 9:53:11
*/
public class Test {
public static void main(String[] args) {
ExecutorService pool = Executors.newFixedThreadPool(2);
Runnable t1 = new MyRunnable("ÕÅÈý", 2000);
Runnable t2 = new MyRunnable("ÀîËÄ", 3600);
Runnable t3 = new MyRunnable("ÍõÎå", 2700);
Runnable t4 = new MyRunnable("ÀÏÕÅ", 600);
Runnable t5 = new MyRunnable("ÀÏÅ£", 1300);
Runnable t6 = new MyRunnable("ÅÖ×Ó", 800);
//Ö´Ðи÷¸öÏß³Ì
pool.execute
Ïà¹ØÎĵµ£º
JavaỊ̈߳ºÏß³ÌջģÐÍÓëÏ̵߳ıäÁ¿
SCJP5ѧϰ±Ê¼Ç
ÒªÀí½âÏ̵߳÷¶ÈµÄÔÀí£¬ÒÔ¼°Ïß³ÌÖ´Ðйý³Ì£¬±ØÐëÀí½âÏß³ÌջģÐÍ¡£
Ïß³ÌÕ»ÊÇָijʱ¿ÌʱÄÚ´æÖÐÏ̵߳÷¶ÈµÄÕ»ÐÅÏ¢£¬µ±Ç°µ÷Óõķ½·¨×ÜÊÇλÓÚÕ»¶¥¡£Ïß³ÌÕ»µÄÄÚÈÝÊÇËæ×ųÌÐòµÄÔËÐж¯Ì¬±ä»¯µÄ£¬Òò´ËÑо¿Ïß³ÌÕ»±ØÐëÑ¡ÔñÒ»¸öÔËÐеÄʱ¿Ì£¨Êµ¼ÊÉÏÖ¸´úÂëÔËÐе½Ê²Ã´µØ· ......
JavaỊ̈߳ºÏ̵߳ĵ÷¶È-ÐÝÃß
JavaÏ̵߳÷¶ÈÊÇJava¶àÏ̵߳ĺËÐÄ£¬Ö»ÓÐÁ¼ºÃµÄµ÷¶È£¬²ÅÄܳä·Ö·¢»ÓϵͳµÄÐÔÄÜ£¬Ìá¸ß³ÌÐòµÄÖ´ÐÐЧÂÊ¡£
ÕâÀïÒªÃ÷È·µÄÒ»µã£¬²»¹Ü³ÌÐòÔ±Ôõô±àдµ÷¶È£¬Ö»ÄÜ×î´óÏ޶ȵÄÓ°ÏìÏß³ÌÖ´ÐеĴÎÐò£¬¶ø²»ÄÜ×öµ½¾«×¼¿ØÖÆ¡£
Ïß³ÌÐÝÃßµÄÄ¿µÄÊÇʹÏß³ÌÈóöCPUµÄ×î¼òµ¥µÄ×ö·¨Ö®Ò»£¬Ïß³ÌÐÝÃß ......
JavaỊ̈߳ºÐÂÌØÕ÷-Ï̳߳Ø
SunÔÚJava5ÖУ¬¶ÔJavaÏ̵߳ÄÀà¿â×öÁË´óÁ¿µÄÀ©Õ¹£¬ÆäÖÐÏ̳߳ؾÍÊÇJava5µÄÐÂÌØÕ÷Ö®Ò»£¬³ýÁËÏ̳߳ØÖ®Í⣬»¹Óкܶà¶àÏß³ÌÏà¹ØµÄÄÚÈÝ£¬Îª¶àÏ̵߳ıà³Ì´øÀ´Á˼«´ó±ãÀû¡£ÎªÁ˱àд¸ßЧÎȶ¨¿É¿¿µÄ¶àÏ̳߳ÌÐò£¬Ï̲߳¿·ÖµÄÐÂÔöÄÚÈÝÏÔµÃÓÈΪÖØÒª¡£
ÓйØJava5Ïß³ÌÐÂÌØÕ÷µÄÄÚÈÝÈ«²¿ÔÚjava.util ......
ÉèÖÃ×¢ÊÍÄ£°åµÄÈë¿Ú£º Window->Preference->Java->Code Style->Code Template È»ºóÕ¹¿ªComments½Úµã¾ÍÊÇËùÓÐÐèÉèÖÃ×¢Ê͵ÄÔªËØÀ²¡£ÏÖ¾Íÿһ¸öÔªËØÖðÒ»½éÉÜ£º
Îļþ(Files)×¢ÊͱêÇ©£º
/**
* @Title: ${file_name}
* @Package ${package_name}
* @Description: ${todo}(ÓÃÒ»¾ä»°ÃèÊö¸ÃÎļ ......
JavaỊ̈߳ºÐÂÌØÕ÷-Ëø£¨Ï£©
ÔÚÉÏÎÄÖÐÌáµ½ÁËLock½Ó¿ÚÒÔ¼°¶ÔÏó£¬Ê¹ÓÃËü£¬ºÜÓÅÑŵĿØÖÆÁ˾ºÕù×ÊÔ´µÄ°²È«·ÃÎÊ£¬µ«ÊÇÕâÖÖËø²»Çø·Ö¶Áд£¬³ÆÕâÖÖËøΪÆÕͨËø¡£ÎªÁËÌá¸ßÐÔÄÜ£¬JavaÌṩÁ˶ÁдËø£¬ÔÚ¶ÁµÄµØ·½Ê¹ÓöÁËø£¬ÔÚдµÄµØ·½Ê¹ÓÃдËø£¬Áé»î¿ØÖÆ£¬ÔÚÒ»¶¨³Ì¶ÈÉÏÌá¸ßÁ˳ÌÐòµÄÖ´ÐÐЧÂÊ¡£
JavaÖжÁдËøÓиö½Ó¿Újava ......