
import java.util.*;
import java.lang.*;
import java.io.*;
 
class Ideone
{
 
	public static void main(String[] args) {
 
		final ActionInterrupt interromper = new ActionInterrupt();
		final ActionFlag flag = new ActionFlag();
		flag.start();
		interromper.start();
 
			try {
			
				int p = 0;
				while(!interromper.isInterrupted()){
					Thread.sleep(33L);
					if(p == 5){
						interromper.interrupt();
						flag.setStop();
					}
					p++;
					System.out.println("MainThread "+p);
					if(p==199){
						break;
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
	}
 
 
 
	static class ActionInterrupt extends Thread{
		@Override
		public void run() {
			int pt = 0;
//			try {
				while(pt != 55){
					try {
						Thread.sleep(10L);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					System.out.println("ActionInterrupt {"+pt+"}");
					pt++;
				}
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
		}
	}
	static class ActionFlag extends Thread{
		private boolean running = true;
 
		public void setStop() {
		    running = false;
		}
 
		@Override
		public void run() {
			int pt = 0;
			while(running){
				try {
					Thread.sleep(10L);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("ActionFlag["+pt+"]");
				pt++;
			}
		}
	}
 
}