测试线程的并发中遇到的问题,java达人请进 加不加synchronized都属于override 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 晕,synchronized和覆盖是没有关系的你这个写的怎么都不可能同步,因为你有2个对象,就是两把锁,线程分别拥有各自的对象,当然不能同步修该一下吧public class testThread extends Thread{public void run() { testThread.todo(); }private synchronized static void todo() { for(int i=0;i<999;i++) { System.out.println(i); }}public static void main(String[] args) { testThread t1=new testThread(); testThread t2=new testThread(); t1.start(); t2.start();}} 楼上说得没错,这样写法毫无意义,除非你的类是singleton的,或者方法是static的,这样保证所有应用是在访问同一个实例或者同一个方法,这样同步才会有作用 谁做过俄罗斯方块的 java写的程序如何编译为exe文件? 刚入大学,向各位前辈请教java和c#的一些问题 MSSQL 关于从数据库中随机抽取数据的问题 急 高手来!! 真郁闷这么简单的题都不会,求助!! 有两个小问题,help! ++++ Java编程思想习题答案 +++++ struts中的javascript写在什么地方?还有............. jbuilder入门女生散分求助,急啊! 一个关于Jbuilder的简单问题! 连接数据库小问题 关于java的环境变量
你这个写的怎么都不可能同步,因为你有2个对象,就是两把锁,线程分别拥有各自的对象,当然不能同步
修该一下吧
public class testThread extends Thread
{
public void run() {
testThread.todo();
}private synchronized static void todo() {
for(int i=0;i<999;i++) {
System.out.println(i);
}
}
public static void main(String[] args) {
testThread t1=new testThread();
testThread t2=new testThread();
t1.start();
t2.start();
}
}