javaÒ»¸ö¶àÏ̵߳ľµäÀý×Ó
import java.io.*;
//¶àÏ̱߳à³Ì
public class MultiThread
{
public static void main(String args[])
{
System.out.println("ÎÒÊÇÖ÷Ïß³Ì!");
//ÏÂÃæ´´½¨Ïß³ÌʵÀýthread1
ThreadUseExtends thread1=new ThreadUseExtends();
//´´½¨thread2ʱÒÔʵÏÖÁËRunnable½Ó¿ÚµÄTHhreadUseRunnableÀàʵÀýΪ²ÎÊý
Thread thread2=new Thread(new ThreadUseRunnable(),"SecondThread");
thread1.start();//Æô¶¯Ïß³Ìthread1ʹ֮´¦ÓÚ¾ÍÐ÷״̬
//thread1.setPriority(6);//ÉèÖÃthread1µÄÓÅÏȼ¶Îª6
//ÓÅÏȼ¶½«¾ö¶¨cpu¿Õ³öʱ£¬´¦ÓÚ¾ÍÐ÷״̬µÄÏß³ÌËÏÈÕ¼Áìcpu¿ªÊ¼ÔËÐÐ
//ÓÅÏȼ¶·¶Î§1µ½10,MIN_PRIORITY,MAX_PRIORITY,NORM_PAIORITY
//ÐÂÏ̼̳߳д´½¨ËýµÄ¸¸Ïß³ÌÓÅÏȼ¶,¸¸Ïß³Ìͨ³£ÓÐÆÕͨÓÅÏȼ¶¼´5NORM_PRIORITY
System.out.println("Ö÷Ï߳̽«¹ÒÆð7Ãë!");
try
{
Thread.sleep(7000);//Ö÷Ïß³Ì¹ÒÆð7Ãë
}
catch (InterruptedException e)
{
return;
}
System.out.println("Óֻص½ÁËÖ÷Ïß³Ì!");
if(thread1.isAlive())
{
thread1.stop();//Èç¹ûthread1»¹´æÔÚÔòɱµôËû
System.out.println("thread1ÐÝÃß¹ý³¤,Ö÷Ïß³ÌɱµôÁËthread1!");
}
else
System.out.println("Ö÷Ïß³Ìû·¢ÏÖthread1,thread1ÒÑÐÑ˳ÐòÖ´ÐнáÊøÁË!");
thread2.start();//Æô¶¯thread2
System.out.println("Ö÷Ïß³ÌÓÖ½«¹ÒÆð7Ãë!");
try
{
Thread.sleep(7000);//Ö÷Ïß³Ì¹ÒÆð7Ãë
}
catch (InterruptedException e)
{
return;
}
System.out.println("Óֻص½ÁËÖ÷Ïß³Ì!");
if(thread2.isAlive())
{
thread2.stop();//Èç¹ûthread2»¹´æÔÚÔòɱµôËû
System.out.println("thread2ÐÝÃß¹ý³¤£¬Ö÷Ïß³ÌɱµôÁËthread2!");
}
else
System.out.println("Ö÷Ïß³Ìû·¢ÏÖthread2,thread2ÒÑÐÑ˳ÐòÖ´ÐнáÊøÁË!");
System.out.println("³ÌÐò½áÊø°´ÈÎÒâ¼ü¼ÌÐø!");
try
{
System.in.read();
}
catch (IOException e)
{
System.out.println(e.toString());
}
}//main
}/
Ïà¹ØÎĵµ£º
Java IOµÄÒ»°ãʹÓÃÔÔò£º
Ò»¡¢°´Êý¾ÝÀ´Ô´£¨È¥Ïò£©·ÖÀࣺ
1¡¢ÊÇÎļþ£º FileInputStream, FileOutputStream, FileReader, FileWriter
2¡¢ÊÇbyte[]£ºByteArrayInputStream, ByteArrayOutputStream
3¡¢ÊÇChar[]: CharArrayReader, CharArrayWriter
4¡¢ÊÇString: StringBufferInputStream, StringReader, StringWriter
5¡¢ ......
(1) ÀàÃûÊ××ÖĸӦ¸Ã´óд¡£×ֶΡ¢·½·¨ÒÔ¼°¶ÔÏ󣨾ä±ú£©µÄÊ××ÖĸӦСд¡£¶ÔÓÚËùÓбêʶ·û£¬ÆäÖаüº¬µÄËùÓе¥´Ê¶¼Ó¦½ô¿¿ÔÚÒ»Æð£¬¶øÇÒ´óдÖм䵥´ÊµÄÊ××Öĸ¡£ÀýÈ磺
ThisIsAClassName
thisIsMethodOrFieldName
ÈôÔÚ¶¨ÒåÖгöÏÖÁ˳£Êý³õʼ»¯×Ö·û£¬Ôò´ ......
JavaÖеÄ23ÖÖÉè¼ÆÄ£Ê½
1¡¢¹¤³§Ä£Ê½£º¿Í»§ ......
Java IOµÄÒ»°ãʹÓÃÔÔò£º
Ò»¡¢°´Êý¾ÝÀ´Ô´£¨È¥Ïò£©·ÖÀࣺ
1¡¢ÊÇÎļþ£º FileInputStream, FileOutputStream, FileReader, FileWriter
2¡¢ÊÇbyte[]£ºByteArrayInputStream, ByteArrayOutputStream
3¡¢ÊÇChar[]: CharArrayReader, CharArrayWriter
4¡¢ÊÇString: StringBufferInputStream, StringReader, StringWriter
5¡¢ ......