日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java基础进阶(文件列表,线程,线程组)编程实例(4篇)

發布時間:2023/12/9 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java基础进阶(文件列表,线程,线程组)编程实例(4篇) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

???? 此處刊登代碼均測試通過,完全準確!
import java.io.*;
public class DirList{
public static void main(String[] args){
try{
File path=new File(".");
/*“.”指當前目錄*/
String[] list;
if(args.length==0)
list=path.list();/*列出當前文件*/
else
?list=path.list(new DirFilter(args[0]));
for(int i=0;i<list.length;i++)
System.out.println(list[i]);
}
catch(Exception e){
e.printStackTrace();
}
}
static class DirFilter implements FilenameFilter{
String afn;
DirFilter(String afn){this.afn=afn;}
public boolean accept(File dir,String name)/*name是文件名*/{
String f=new File(name).getName();
/*getName得到文件名的非目錄部分,只有文件名*/
return f.indexOf(afn)!=-1;
}
}
}
---------------------------------------------------------------------------------------------------------------------------------------
public class SimpleRunnable implements Runnable{
private String message;
public static void main(String[] args){
SimpleRunnable r1=new SimpleRunnable("Hello");
Thread t1=new Thread(r1);
t1.start();
for(;;)/*死循環*/{
System.out.println("Bye-bye");
}
}
public SimpleRunnable(String message){
this.message=message;
}
public void run(){
for (;;)/*死循環*/{
System.out.println(message);
}
}
}

---------------------------------------------------------------------------------------------------------------------------------------

public class MethodText{
public static void main(String[] args){
FirstThread first=new FirstThread();
SecondThread second=new SecondThread();
first.start();
second.start();
try{
System.out.println("Waiting for first thread to finish!");
first.join();
System.out.println("It's a long wait!");

System.out.println("Waking up second thread...");
second.resume();
System.out.println("Waiting for second thread to finish!");
second.join();
}catch(InterruptedException e){
}
System.out.println("I'm ready to finish too.");
}
}
class FirstThread extends Thread{

public void run(){
try{
System.out.println("First thread starts running!");
sleep(10000);
System.out.println("First thread finishes running!");
}catch(InterruptedException e){
}
}
}
class SecondThread extends Thread{

public void run(){
System.out.println("Second thread starts running.");
System.out.println("Second thread suspend itself.");
suspend();
System.out.println("Second thread runs again and finishes.");
}
}


---------------------------------------------------------------------------------------------------------------------------------------
public class Grp implements Runnable{
public void run(){
for (;;){
System.out.println("thread"+Thread.currentThread().getName());
try{
Thread.sleep(500);
}catch(Exception e){
}
}
}
public static void main(String[] args)
{
ThreadGroup g=new ThreadGroup("My Group");
Runnable r=new Grp();
Thread t=new Thread(g,r);
t.start();
t=new Thread(g,r);
t.start();
for(;;){
try{
Thread.sleep(5000);
}catch(Exception e){
}
g.suspend();
System.out.println("thread"+Thread.currentThread().getName());
try{
Thread.sleep(5000);
}catch(Exception e){
}
g.resume();
}
}
}





---------------------------------------------------------------------------------------------------------------------------------------

轉載于:https://www.cnblogs.com/shiyangxt/archive/2008/06/09/1216339.html

總結

以上是生活随笔為你收集整理的java基础进阶(文件列表,线程,线程组)编程实例(4篇)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。