加入收藏  广告服务  关于我们
 2004-11-11

[coding] Threading differences in C# and Java

发表:不详   阅读:次  关键字:不详   字体:[ ]

C# 

using System.Threading;
public class myThread    
{
    static public void RunThread()    
    { /* do work */ }
}
public class TestThread
{
        public static main( )
        {
                Thread NotifyThread = new Thread(new ThreadStart(myThread.RunThread));
        }
}



Java
public class myThread    implements Runable
{
    public void run()    //must override run()
    { 
        try
        {
            /* do work */
            Thread.sleep( SLEEP_TIME); // let the other threads run.
         }
        catch( InterruptedException e ) { ... }
      }
}
public class TestThread
{
        public static main( )
        {
            Runable run = new myThread();
            Thread thread=new Thread( run );
            thread.start(); // will invoke myThread.run()
        }
}

 热门文章
 推荐信息