Java SEÖеÄÏß³Ì
1.´´½¨Ïß³Ì
·½Ê½Ò»£ºÍ¨¹ýThreadµÄ×ÓÀà´´½¨£¬´ËʱÐèÒªÔÚThreadÀàµÄ×ÓÀàÖÐÖØд¸¸ÀàµÄpublic void run()·½·¨
·½Ê½¶þ£ºÖ±½ÓʹÓÃThreadÀà´´½¨
ÓÃÕâÖÖ·½Ê½´´½¨Ïß³Ìʱ£¬Í¨³£ÒªÊ¹ÓÃÒÔϹ¹Ôì·½·¨£ºThread(Runnable a) //RunnableÊÇÒ»¸ö½è¿Ú
´ËʱÐèÒªÔÚʹÓÃÁËRunnable½Ó¿ÚµÄÀàÖÐÖØдThreadÀàµÄpublic void run()·½·¨
2.ThreadÀà³£Óõķ½·¨
start()£ºÆô¶¯Ị̈߳¬Ò»°ãÊÇÔÚÖ÷º¯ÊýÖÐÆô¶¯
run()£ºÓÃÀ´¹æ¶¨Ï̱߳»Æô¶¯ÒԺ󣬸ÃÏß³ÌËùÒªÖ´ÐеľßÌå²Ù×÷
setName(String s)£º¸øÏß³ÌÈ¡Ãû
getName()£º·µ»Øµ±Ç°Ï̵߳ÄÃû³Æ
sleep(int millsecond)£ºÊÇThreadÀàµÄÀà·½·¨£¬¸Ã·½·¨ÊÇÏß³ÌÔÚÆärun()·½·¨Öо³£µ÷Óõķ½·¨£¬±íʾÏß³ÌÐÝÃßÒ»¶Îʱ¼ä£¬
millsecondÊÇÆäÐÝÃߵĺÁÃëÊý£»Ëü±ØÐëÔÚtry--catchÓï¾äÖб»µ÷Óã¬Òì³£Ààͨ³£ÎªInterruptedException
isAlive()£ºÅжϸÃÏß³ÌÊÇ·ñ´¦ÓÚÔËÐÐ״̬
currentThread()£º·µ»Øµ±Ç°ÕýÔÚÕ¼ÓÃCPU×ÊÔ´µÄÏß³Ì
interrupt()£ºµ±Ä³¸öÏ̵߳÷ÓÃsleep()·½·¨´¦ÓÚÐÝÃß״̬ʱ£¬¸ÃÏ߳̿ÉÒÔʹÓÃinterrupted()·½·¨³³ÐÑ×Ô¼º£¬¼´µ¼ÖÂÐÝÃßµÄÏ̷߳¢Éú
InterruptedExceptionÒì³££¬´Ó¶ø½áÊøÐÝÃߣ¬ÖØÐÂÅŶӵȴýCUP×ÊÔ´
3.Ïß³Ìͬ²½
ÊÇÖ¸Èô¸É¸öÏß³ÌÐèҪʹÓÃͬһ¸ösynchronizedÐÞÊεķ½·¨
ÓÃsynchronizedÐÞÊεķ½·¨³ÆΪͬ²½·½·¨
Ïà¹ØÎĵµ£º
/**
* ### Õæ難µÄ題Ä¿: ¹·Æ¨ÑÝËã·¨ (測資ºÜ機車)
* 測驗結¹û: x.xx0 ms
* 測驗ÈÕÆÚ: 200y-mm-dd
* @author Raymond Wu (Сè°Íè)
*/
public class Main {
// 輸Èë緩衝區 (緩衝¿Õ ......
(×¢Ò⣺ÏÂÃæÎļþ¶¼ÔÚf:\myjavaÖУ©
{
3¸öÔ´Îļþ£ºMyApp.java,MyLib.java,PrintSchool.java;
½¨Îļþ¼Ðorg\Jie
ÆäÖÐMyLibºÍPrintSchool·ÅÔÚ°üorg.JieÖУ¨import org.Jie)
ÔÚcmd.exeÖÐÔËÐÐ
javac -d org\Jie MyLib.java //ÔÚorg\Jie\org\jieÉú³ÉÁËMyLib.classÎļþ£¬½«¸ÃÎļþ ......
BlockingQueueÊÇÒ»¸ö½Ó¿Ú£¬Ëü´ÓQueue¼Ì³Ð¶øÀ´£¬
°üº¬ÁËQueueµÄËùÓй¦ÄÜ£¬²¢ÔÚQueueµÄ»ù´¡ÉÏÌṩÁË2¸öÐµĹ¦ÄÜ£º
1. ¼ìË÷ÔªËØʱµÈ´ý¶ÓÁбäΪ·Ç¿Õ
2. ´æ´¢ÔªËØʱµÈ´ý¿Õ¼ä±äµÃ¿ÉÓá£
ÏÂÃæ³Â¼Ò»Ð©JDKÎĵµÖйØÓÚBlockingQueueµÄ½éÉÜ£º
BlockingQueue ¿ÉÒÔÊÇÏÞ¶¨ÈÝÁ¿µÄ¡£ËüÔ ......
ÎÒ½ñÌìѧϰÁËÐìÀÏʦ½«µÄhibernate¿ò¼Ü֪ʶ£¬ÎÒ×öÁ˼òµ¥µÄ±Ê¼Ç£º
¼¯ºÏÊôÐÔ´óÖ·ÖΪ¶þÖÖ£º
µ¥´¿µÄ¼¯ºÏÊôÐÔ£¬ÏñList,Set»òÊý×éµÈ¼¯ºÏÊôÐÔ¡£
2,Map¼¯ºÏÊôÐÔ£¬Ã¿¸öÊôÐÔÖµ¶àÓÐÏà¶ÔÓ¦µÄKeyÓ³Éä¡£
&nb ......