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();
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个线程。。你可以开多个线程测试。。
我的这个是为了测试线程同步做的。。
使用httpclient发消息吧