http://blog.csdn.net/testcs_dn/article/details/42526549
java线程使用示例——最简单的线程
线程使用示例一:
- public class ThreadTest {
-
- public static void main(String[] args) {
-
- new Thread() {
- public void run() {
- while (true) {
- try {
- System.out.println("线程输出");
-
-
- Thread.sleep(2 * 1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- };
- }.start();
- }
-
- }
线程使用示例二:
-
- Thread t1 = new Thread(new Runnable(){
- public void run(){
- System.out.println("Mythread 线程t1");
- while(true){
- Singleton3 single3 = Singleton3.getInstance(null);
- System.out.println("线程t1 >> " + single3.toString());
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
-
- e.printStackTrace();
- }
- }
-
- }
- });
- t1.start();