- public class Main
- {
- public static void main(String[] args) throws Exception
- {
- Runner mRunner = new Runner();
-
-
-
- new Thread(mRunner).start();
- for (int i = 0; i < 1000; i++)
- {
- System.out.println(" ------" + Thread.currentThread());
- }
-
- mRunner.makeStop();
- }
- }
-
- 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