Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Java¶àÏ̵߳ÄÏà¹Ø»úÖÆ

Ò» Ï̵߳Ļù±¾¸ÅÄî
Ïß³ÌÊÇÒ»¸ö³ÌÐòÄÚ²¿µÄ˳Ðò¿ØÖÆÁ÷.Ò»¸ö½ø³ÌÏ൱ÓÚÒ»¸öÈÎÎñ,Ò»¸öÏß³ÌÏ൱ÓÚÒ»¸öÈÎÎñÖеÄÒ»ÌõÖ´Ðз¾¶.£»¶à½ø³Ì:ÔÚ²Ù×÷ϵͳÖÐÄÜͬʱÔËÐжà¸öÈÎÎñ(³ÌÐò)£»¶àÏß³Ì:ÔÚͬһ¸öÓ¦ÓóÌÐòÖÐÓжà¸ö˳ÐòÁ÷ͬʱִÐУ»JavaµÄÏß³ÌÊÇͨ¹ýjava.lang.ThreadÀàÀ´ÊµÏֵģ»JVMÆô¶¯Ê±»áÓÐÒ»¸öÓÉÖ÷·½·¨(public static void main(){})Ëù¶¨ÒåµÄỊ̈߳»¿ÉÒÔͨ¹ý´´½¨ThreadµÄʵÀýÀ´´´½¨ÐµÄỊ̈߳»Ã¿¸öÏ̶߳¼ÊÇͨ¹ýij¸öÌض¨Thread¶ÔÏóËù¶ÔÓ¦µÄ·½·¨run()À´Íê³ÉÆä²Ù×÷µÄ,·½·¨run()³ÆΪÏß³ÌÌ壬ͨ¹ýµ÷ÓÃThreadÀàµÄstart()·½·¨À´Æô¶¯Ò»¸öÏ̡߳£
¶þ Ï̵߳Ĵ´½¨ºÍÆô¶¯
¿ÉÒÔÓÐÁ½ÖÖ·½Ê½´´½¨ÐµÄÏß³Ì:
µÚÒ»ÖÖ:
1.¶¨ÒåÏß³ÌÀàʵÏÖRunnable½Ó¿Ú
2.Thread myThread = new Thread(target);   //targetΪRunnable½Ó¿ÚÀàÐÍ
3.RunnableÖÐÖ»ÓÐÒ»¸ö·½·¨:public void run();ÓÃÒÔ¶¨ÒåÏß³ÌÔËÐÐÌå
4.ʹÓÃRunnable½Ó¿Ú¿ÉÒÔΪ¶à¸öÏß³ÌÌṩ¹²ÏíµÄÊý¾Ý
5.ÔÚʵÏÖRunnable½Ó¿ÚµÄÀàµÄrun()·½·¨¶¨ÒåÖпÉÒÔʹÓÃThreadµÄ¾²Ì¬·½·¨public static Thread currentThread();»ñÈ¡µ±Ç°Ï̵߳ÄÒýÓÃ
µÚ¶þÖÖ:
1.¿ÉÒÔ¶¨ÒåÒ»¸öThreadµÄ×ÓÀಢÖØдÆärun·½·¨Èç:
class MyThread extends Thread {
public void run() {...}
}
2.È»ºóÉú³É¸ÃÀàµÄ¶ÔÏó:
MyThread myThread = new MyThread();
Èý Ï߳̿ØÖƵĻù±¾·½·¨
isAlive():ÅжÏÏß³ÌÊÇ·ñ»¹"»î"×Å
getPriority():»ñµÃÏ̵߳ÄÓÅÏȼ¶ÊýÖµ
setPriority():ÉèÖÃÏ̵߳ÄÓÅÏȼ¶ÊýÖµ
Thread.sleep():½«µ±Ç°Ïß³Ì˯ÃßÖ¸¶¨ºÁÃëÊý
join():µ÷ÓÃijÏ̵߳ĸ÷½·¨,½«µ±Ç°Ïß³ÌÓë¸ÃÏß³Ì"ºÏ²¢",¼´µÈ´ý¸ÃÏ߳̽áÊø,ÔÙ»Ö¸´µ±Ç°Ï̵߳ÄÔËÐÐ
yield():Èóöcpu,µ±Ç°Ï߳̽øÈë¾ÍÐ÷¶ÓÁеȴýµ÷¶È
wait():µ±Ç°Ï߳̽øÈë¶ÔÏóµÄwait pool
notify()/notifyAll():»½ÐѶÔÏóµÄwait poolÖеÄÒ»¸ö/ËùÓеȴýÏß³Ì
ËÄ Ïß³Ìͬ²½
ʵÏÖÉú²úÕßÏû·ÑÕßÎÊÌâÀ´ËµÃ÷Ïß³ÌÎÊÌâ,¾ÙÀýÈçÏÂËùʾ:
/**
* Éú²úÕßÏû·ÑÕßÎÊÌâ
*/
package com.basic.thread;
/**
* @author johnston678
*
* @version 2009-05-06
*/
public class ProducerConsumer {
/**
* @param args
*/
public static void main(String[] args) {
ProductBox pb = new ProductBox();
Producer p = new Producer(pb);
Consumer c = new Consumer(pb);

Thread pThread =


Ïà¹ØÎĵµ£º

javaÐÔÄÜ·ÖÎö

    Ô­ÎĵØÖ·£ºhttp://www.javaeye.com/topic/626801 Ò»Ö±ÔÞ̾Sun¶Ô´ý¼¼ÊõµÄÑϽ÷ºÍÓÅÑÅ£¨¿ÉÁ¯µÄSun£©¡£Sun JDKÖÐJava¿âµÄÔ´´úÂ룬Á¬×¢ÊͶ¼ÇåÇå³þ³þ¡¢¹æ¹æ·¶·¶£¬javadoc×¢½âµÄʹÓÃҲһ˿²»¹¶£¬¶ÁÆðÀ´ºÜÊìÊæ·þ¡£Òò´Ë£¬ÔÚÈÕ³£¹¤×÷ºÍѧϰÖУ¬¾­³£¶Á¶Á Java¿âµÄÔ´´úÂ룬²»ÒàÀÖºõ£¿Èç¹ûÓöµ½¹îÒìÎÊÌ⣬Դ´úÂë ......

´«ÖDz¥¿ÍJAVAÅàѵOAÏîÄ¿2010 5 12


´«ÖDz¥¿ÍJAVAÅàѵOAÏîÄ¿2010-5-12
½ñÌì»»Á˸öнÌÊÒ£¬ÖÕÓÚ½áÊøÁËÃÆÈȵĿÕÆøÁË¡£ÒÔÇ°½ÌÊÒ¿Õµ÷´ó´óµÄÓÐÎÊÌ⣬ÏÖÔÚºÃÁË£¬¿ÉÒÔÒ»Ïí¿Õµ÷µÄÁ¹Ë¬£¬Ö»²»ÊÇΨһÃÀÖв»×ãµÄÊÇ£¬¾ÓÈ»ÓõIJ»ÊǸñÁ¦¿Õµ÷¡£ÔÚ¸ñÁ¦¿Õµ÷´ôÁËËÄÄ꣬ËäÈ»ÔÚÄǶùûÓз¢»Ó³öÎÒ¸üºÃµÄˮƽ£¬µ«ÊÇÈ˱Ͼ¹ÊÇÓиÐÇéµÄ£¬ÎÒÒ²ºÜ°®ÄǸö¸ñÁ¦£¬´ó¹«Ë¾£¬´óÆøÆÇ£¬ÌرðÊÇ£¬ÎÒà ......

´«ÖDz¥¿ÍJavaÅàѵ Servlet

ÔçÉÏÆð´²ÓеãÍíÁË£¬µ½Ñ§Ð£µÃʱºò¶¼8£º50ÁË£¬Ò»½ø½ÌÊÒ¿´¼ûÕÅТÏéÀÏʦÔÚ½ÌÊÒÀï¸øͬѧÃǽâ¾öÎÊÌ⣬²»¼ûÁËÀϱϵÄÉíÓ°£¬»¹ÒÔΪ×ß´í½ÌÊÒÁËÄØ£¬°´Àí˵Õâ¸öʱºòÀϱÏÓ¦¸ÃÔçÀ´Á˲ÅÊÇ£¬Ò»ÎʲÅÖªµÀÊDZÏÀÏʦ²¡ÁË,È¥Ò½Ôº¼ì²éÈ¥ÁË£¬Ï£Íû±ÏÀÏʦÄÜÔçµãºÃÆðÀ´£¡
½ñÌìÊÇÕÅÀÏʦ¸øÎÒÃÇÉϿΣ¬ÉîÈëÆÊÎöservlet£¬ÔÚûÀ´´«ÖDz¥¿Í֮ǰ¿´¹ý²»ÉÙÒÔÇ°ÕÅÀ ......

JAVAÓÅ»¯±à³Ì


java´úÂëÓÅ»¯±à³Ì
1.JVM ¹ÜÀíÁ½ÖÖÀàÐ͵ÄÄÚ´æ:¶ÑÄÚ´æ(heap),Õ»ÄÚ´æ(stack),¶ÑÄÚÔÚÖ÷ÒªÓÃÀ´´æ´¢³ÌÐòÔÚÔËÐÐʱ´´½¨»òʵÀý»¯µÄ¶ÔÏóÓë±äÁ¿.¶øÕ»ÄÚ´æÔòÊÇÓÃÀ´´æ´¢³ÌÐò´úÂëÖÐÉùÃ÷Ϊ¾²Ì¬(static)(»ò·Ç¾²Ì¬)µÄ·½·¨.
2.JVM ÖжÔÏóµÄÉúÃüÖÜÆÚ,´´½¨½×¶Î,Ó¦Óý׶Î,²»¿ÉÊӽ׶Î,²»¿Éµ½´ï½×¶Î,¿ÉÊÕ¼¯½×¶Î,ÖÕ½á½×
¶Î,ÊͷŽ׶Î
3.±ÜÃâÔÚÑ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ