multithreadingDemo

class Count implements Runnable
{
   Thread mythread ;
   Count()
   {
      mythread = new Thread(this, "my runnable thread");
      System.out.println("my thread created" + mythread);
      mythread.start();
   }
   public void run()
   {
      try
      {
        for (int i=0 ;i<10;i++)
        {
          System.out.println("Printing the count " + i);
          Thread.sleep(1000);
        }
     }
     catch(InterruptedException e)
     {
        System.out.println("my thread interrupted");
     }
     System.out.println("mythread run is over" );
   }
}

  

class RunnableExample
{
    public static void main(String args[])
    {
       Count cnt = new Count();
       try
       {
          while(cnt.mythread.isAlive())
          {
            System.out.println("Main thread will be alive till the child thread is live");
            Thread.sleep(1500);
          }
       }
       catch(InterruptedException e)
       {
          System.out.println("Main thread interrupted");
       }
       System.out.println("Main thread run is over" );
    }
}

  

my thread createdThread[my runnable thread,5,main]
Main thread will be alive till the child thread is live
Printing the count 0
Printing the count 1
Main thread will be alive till the child thread is live
Printing the count 2
Main thread will be alive till the child thread is live
Printing the count 3
Printing the count 4
Main thread will be alive till the child thread is live
Printing the count 5
Main thread will be alive till the child thread is live
Printing the count 6
Printing the count 7
Main thread will be alive till the child thread is live
Printing the count 8
Main thread will be alive till the child thread is live
Printing the count 9
mythread run is over
Main thread run is over
时间: 2024-08-24 21:27:21

multithreadingDemo的相关文章

iOS-git

安装Git 1.方法一:安装homebrew,然后通过homebrew安装Git. 第一步:在终端输入如下命令安装homebrew 1 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 第二步:执行下面的命令,通过Homebrew安装Git. 1 $ brew install git 具体方法请参考homebrew的文档:http://brew.sh/ Ho

劣倥戮阉盼ds0zijhzxx6

在对国有企业改革的实施过程中,国企员工持股占有非常重要的地位,因此,最初国资委和财政部等部门参与制订了员工持股部分的政策. 在不久前落幕的2016年全国两会上,国务院国有企业改革领导小组组长马凯对外界表示:"去年是国企改革方案制定的一年,今年是扎扎实实的落实年." 前述国资委人士认为:"一般的企业不适合员工持股,一个万人大厂,所有员工都持股,没有意义.容易造成福利性的持股.实际上,改革30年,已经证明,全员持股不是一个好办法,要分企业.分行业,根据它的特点进行持股."

多线程技术交流提纲

多线程技术交流提供:http://lazio10000.github.io/tech/Multihreading demo下载:http://lazio10000.github.io/tech/Multihreading/MultithreadingDemo.zip 多线程技术交流提纲

Git 的使用教程

Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理. 安装Git 1.方法一:安装homebrew,然后通过homebrew安装Git. 第一步:在终端输入如下命令安装homebrew 1 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 第二步:执行下面的命令,通过Homebrew安装Git. 1 $ brew inst