Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main

Python
C++

JAVA


PHP
SQL
Assignments

ThreadExamples


ProblemThread.java

package basicExamples;

public class ProblemThread extends Thread {
	static int counter = 0;
	static Integer foo = new Integer(0);
	int i;

	public ProblemThread(int i) {
		super();
		this.i = i;
	}
	public void run() {
		System.out.println("Thread "+i+": Hai.");
		doStuff();
	}
	private void doStuff() {
		//synchronized (foo) {
			counter++;
			if(counter%2==0) {
				System.out.println("Thread "+i+": counter is even.");
				System.out.println("Thread "+i+": counter is "+counter+" (See!  I told you it was EVEN)");
			} else {
				System.out.println("Thread "+i+": counter is ODD.");
				System.out.println("Thread "+i+": counter is "+counter+" (See!  I told you it was ODD)");
				
			}
			System.out.println("Thread "+i+": k. thnx. bye.");
		//}
		
	}
}