zoukankan      html  css  js  c++  java
  • Java Start and Stop a Thread

    • public class Main 
    •     public static void main(String[] args) throws Exception 
    •     { 
    •         Runner mRunner = new Runner(); 
    •         // Allocates a new Thread object. 
    •         // mRunner - the object whose run method is called. 
    •         // start() - causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread. 
    •         new Thread(mRunner).start(); 
    •         for (int i = 0; i < 1000; i++) 
    •         { 
    •             System.out.println("     ------" + Thread.currentThread()); 
    •         } 
    •         // Set message to stop the thread. 
    •         mRunner.makeStop(); 
    •     } 
    • // The Runnable interface should be implemented by any class whose instances are intended to be executed by a thread. 
    • class Runner implements Runnable 
    •     boolean makeStop = false
    •     @Override 
    •     public void run() 
    •     { 
    •         while (true
    •         { 
    •             System.out.println("++++++      " + Thread.currentThread()); 
    •             if (makeStop == true
    •             { 
    •                 return
    •             } 
    •         } 
    •     } 
    •     public void makeStop() 
    •     { 
    •         this.makeStop = true
    •     } 
    • }
    转:http://programs.blog.51cto.com/785537/439667
  • 相关阅读:
    命令行中邮件的收发
    关于location对象
    正则表达式
    一家初创公司的 CTO 应当做什么?
    移动数据网络质量的国家奖牌榜
    MFQ&PPDCS测试分析和测试设计框架l学习记录
    Python学习笔记之基本语法学习1
    《用Python做HTTP接口测试》学习感悟
    我的中台的理解
    中台与平台的区别
  • 原文地址:https://www.cnblogs.com/jiezzy/p/2654403.html
Copyright © 2011-2022 走看看