用JAVA写一个多线程程序,输出1,2,3,4,5,6,7。。。 怎么写才是最好的结果呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 LZ, 这个有意义么.? 一个for单线程不就ok了? 写两个多线程,一个输出奇数,一个输出偶数,再调用一下sleep()方法不就ok了。还有什么好的方法?期待高手解答…… public class ThreadTest implements Runnable { private static int tmep = 0; public void run() { int temp = this.returntemp(); if (temp < 11) { System.out.println((temp + 1+" ")); tmep++; } } private synchronized int returntemp() { return this.tmep; } public static void main(String[] args) { ThreadTest t1 = new ThreadTest(); ThreadTest t2 = new ThreadTest(); for (int i = 0; i < 5; i++) { t1.run(); t2.run(); } }} JAVA如何调用这个CLASS? 感谢版主,虽然你结掉了我的帖子,但你的答案最准确,单独感谢您算了。 jboss服务器报错,如何解决 【散分】庆祝升2星 值得高手研究的javamail的中文题的搜索问题! tomcat启动时是怎么调用server.xml文件的? jdbc的配置问题[急] 关于用JavaBeans连数据源操作数据库的郁闷 [struts]问struts中标签<bean:message>什么意思 大家帮忙看下,如此代码在多线程下是否能兼顾效率和稳定呢? 请教高手几个SQL语句的写法 急!!! 欢迎你加入我们的创业团队
还有什么好的方法?期待高手解答……
int temp = this.returntemp();
if (temp < 11) {
System.out.println((temp + 1+" "));
tmep++;
}
} private synchronized int returntemp() {
return this.tmep;
} public static void main(String[] args) {
ThreadTest t1 = new ThreadTest();
ThreadTest t2 = new ThreadTest();
for (int i = 0; i < 5; i++) {
t1.run();
t2.run();
}
}
}