class FelipeTestThread {

	//volatile keyword not needed any more
	private boolean running = true;

	public void test() {
		// thread 1
		new Thread(new Runnable() {
			public void run() {
				int counter = 0;
				while (isRunning()) {
					counter++;
				}
				System.out.println("Thread 1 finished. Counted up to " + counter);
			}
		}).start();
		
		// thread 2
		new Thread(new Runnable() {
			public void run() {
				// Sleep for a bit so that thread 1 has a chance to start
				try
				{
					Thread.sleep(100);
				} catch (InterruptedException ignored) {
					// do nothing
				}
				System.out.println("Thread 2 finishing");
				//running = false;
				stopRunning();
			}
		}).start();
	}
	
	public static void main(String[] args) {
		new FelipeTestThread().test();
	}
	
	public void stopRunning() {
		synchronized(this) {
		  running = false;
		}
	}
	
	public boolean isRunning() {
		synchronized(this) {
			return (running == true);
		}
	}
}
