多线程接口Runnable
作者:
招风小妖怪 | 来源:发表于
2019-07-12 08:43 被阅读0次
匿线程方式
class Demo11
{
public static void main(String s[])
{
new Thread(new Runnable(){
public void run()
{
while(true)
{
System.out.println(1);
}
}
}).start();
}
}
类实现接口方式
class A implements Runnable
{
public void run()
{
for(int i=0;i<100;i++)
{
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
System.out.print(i+"\t");
}
}
}
class Demo11
{
public static void main(String s[])
{
A a = new A();
Thread Tr = new Thread (a);
Tr.start();
}
}
本文标题:多线程接口Runnable
本文链接:https://www.haomeiwen.com/subject/ffydkctx.html
网友评论