a simple example of thread and runnable in java
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了a simple example of thread and runnable in java相关的知识,希望对你有一定的参考价值。
package com.user;
public class Thread_Thread {
public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread m_t=new MyThread();
m_t.setName("thread");
m_t.start();
MyRunnable myRunnable=new MyRunnable();
Thread m_r=new Thread(myRunnable);
m_r.setName("runnable");
m_r.start();
System.out.println("Thread and runner");
}
static class MyThread extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
// super.run();
System.out.println(Thread.currentThread().getName()+" begins------");
int i = 1;
while(i<7){
i++;
if(i%3==0){
System.out.println(Thread.currentThread().getName()+" is working!!!");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.out.println(Thread.currentThread().getName()+" ends======");
}
}
static class MyRunnable implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(Thread.currentThread().getName()+" begins------");
System.out.println(Thread.currentThread().getName()+" ends======");
}
}
}
run the java program:
以上是关于a simple example of thread and runnable in java的主要内容,如果未能解决你的问题,请参考以下文章
a simple example for spring AOP
python simple factory mode example
A simple introduction to Three kinds of Delegation of Kerberos
zoj 1763 A Simple Question of Chemistry
A simple model for describing basic sources of possible performance problems