欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java匿名类 博客分类: 基础知识

程序员文章站 2024-03-05 22:00:01
...

最后看到了这种new Thread(new Runnable()的用法,这里记录一下。

 

class test {
        public static void main(String [] arg){
                System.out.println("Hello.");
                new Thread(new Runnable(){
                        public void run(){
                                System.out.println("I'm the Runnable run.!");
                                try {
                                Thread.sleep(1000);
                                } catch (Throwable e){
                                        e.printStackTrace();
                                }
                                System.out.println("I'm the Runnable run..!");
                        }
                }).start();
                System.out.println("Hello ..");
        }
}

上一篇: JAVA实现异步调用实例代码

下一篇: