文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>[Java] Thread

[Java] Thread

时间:2010-09-10  来源:web_surf

  1. Documents
    • Reference
      http://cupi2.uniandes.edu.co/site/images/recursos/javadoc/j2se/1.5.0/docs/api/java/lang/Thread.html
    • Samples
      • http://walsh.javaeye.com/blog/220212
      • http://www.ctba.cn/blog/entry/1475
    • xxx
  2. Use Thread
    class MyThread extends Thread
    {
        private int m_keeps;
        public MyThread(int keeps)
        {
            m_keeps = keeps;
       }

       public void run()
        {
            while(true)
            {  
             try
                {
                 System.out.println(":" + new Date(System.currentTimeMillis()));
                 Thread.sleep(pauseTime);
              }
                catch(Exception e)
                {
                System.out.println(e);
             }
            }
        }

      static public void main(String args[])
       {
            MyThread thread = new MyThread(10000);
          thread.start();
      }
    }

  3. Use Runnable
    class MyRunnable extends Runnable
    {
        private int m_keeps;
        public MyRunnable(int keeps)
        {
            m_keeps = keeps;
       }

       public void run()
        {
            while(true)
            {  
             try
                {
                 System.out.println(":" + new Date(System.currentTimeMillis()));
                 Thread.sleep(pauseTime);
              }
                catch(Exception e)
                {
                System.out.println(e);
             }
            }
        }

      static public void main(String args[])
       {
            Thread thread = new Thread(new MyRunnable(10000));
          thread.start();
      }
    }
  4. Notes:
    • You CANNOT modity ui elements directly in thread
    • xxx
  5. xxx
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载