java如何模拟一个多线程环境
想建一个java web项目,然后模拟一下多线程的环境,然后debug方式去运行
看看运行过程如何,请项目代码
------解决方案--------------------
public class TestThreadSafe implements Runnable {
	static int count=0;
	/**
	 * @param argss
	 */
	public static void main(String[] args) {
		TestThreadSafe a = new TestThreadSafe();
		Thread t1 = new Thread(a);
		Thread t2= new Thread(a);
		t1.start();
		t2.start();		
	}
	public  void run() {
		while (true) {
			count++;
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(count);
		}
	}
}
代码只用了2个线程。。你可以开多个线程测试。。
我的这个是为了测试线程同步做的。。